こんにちは私はIOSで新しいです。私は状態リストのテーブルビューを作成しています。ボタンをクリックすると、ポップアップでTableViewが表示されます。状態リストを作成するためのコードは、テーブル作成コードの場合IOSで選択されたチェックTableViewCellを表示する方法(目的c)
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
selectedState = [NSMutableArray new];
UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth-50, screenHeight-50)];
mytableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, screenWidth-50, screenHeight-100)];
mytableview.delegate =self;
mytableview.dataSource=self;
[contentView addSubview:mytableview];
UIButton *save = [[UIButton alloc] initWithFrame:CGRectMake(0, screenHeight-100, screenWidth-50, 50)];
[save setTitle:@"SAVE" forState:UIControlStateNormal];
save.titleLabel.font = [UIFont systemFontOfSize:14];
[save setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[save addTarget:self action:@selector(saveActionForState:) forControlEvents:UIControlEventTouchUpInside];
[save setBackgroundColor:[UIColor colorWithRed:41.0/255.0 green:178.0/255.0 blue:165.0/255.0 alpha:1.0]];
[contentView addSubview:save];
[[KGModal sharedInstance] showWithContentView:contentView andAnimated:YES];
は、テーブルセルの選択にIOSのセルを確認
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [stateList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CRTableViewCellIdentifier = @"cellIdentifier";
if(selectStateButton ==1){
CRTableViewCell *cell = (CRTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CRTableViewCellIdentifier];
if (cell == nil) {
cell = [[CRTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CRTableViewCellIdentifier];
}
NSString *text = [stateList objectAtIndex:[indexPath row]];
cell.textLabel.font = [UIFont systemFontOfSize:12.0];
cell.isSelected = [selectedState containsObject:text] ? YES : NO;
cell.textLabel.text = text;
return cell;
}
}
です。このように見て
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectStateButton ==1){
//[selectedStatesForSelect2 removeAllObjects];
NSString *text = [stateList objectAtIndex:[indexPath row]];
NSInteger indexings = [indexPath row]+1;
if ([selectedState containsObject:text]){
[selectedState removeObject:text];
[selectedStatesId removeObject:[NSString stringWithFormat:@"%ld", (long)indexings]];
}else{
//NSLog(@"count%lu indexing %@",(unsigned long)[selectedState count],selectedStatesId);
[selectedState addObject:text];
[selectedStatesId addObject:[NSString stringWithFormat:@"%ld", (long)indexings]];
[selectedStatesForSelect2 addObject:[NSString stringWithFormat:@"%ld", (long)indexings]];
NSLog(@"select%@count%lu",selectedStatesForSelect2,(unsigned long)[selectedState count]);
if([selectedState count] > 3){
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Hold On..." message:@"You can't select more than three states." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[selectedState removeObject:text];
[selectedStatesId removeObject:[NSString stringWithFormat:@"%ld", (long)indexings]];
}
}
}
。ユーザーが最初に選択すると、非常にうまく動作します。しかし、テーブルビューを閉じた後、ユーザが再び状態リストを開くと、前の選択されたアイテムを表示したい。それは正しく動作しません。私はチェック "CRMultiRowSelector"のためのライブラリを使用しています。私を助けてください。
ウダイ・クマール私のcoding.Itを試してみてくださいを何度も試みた完璧
作品this.It何与えます完璧に動作します。 – user3182143