私はこれを約3時間続けてきましたが、ついにタオルを投げています。私の見解では 2UITableView
つあります。1 つはコメントを残すためのフォーラム ボードで、もう 1 つはUITableView
人々に言及するために使用されます。私が抱えている問題tableview counts
は、テーブルビューの 1 つだけを更新したい場合でも、両方が影響を受けていることです。
デリゲート/データソースを設定しましたviewdidload
self.mentionTableView.delegate = self;
self.mentionTableView.dataSource = self;
self.mentionTableView.tag = 1;
self.forumTable.delegate = self;
self.forumTable.dataSource = self;
self.forumTable.tag = 2;
そして、データを取得するfeedArray
場所を実際にロードしない場合、言及部分は完全に機能します。<のforumTable
場合はすべて正常に動作しますが、>の場合はクラッシュし、これがエラーになりますmatchedNames.count
feedArray.count
matchedNames.count
feedArray.count
-[__NSCFArray objectAtIndex:]: index (1) beyond bounds (1)
つまり、アイテムが 1 つしかなく、複数あることを意味しfeedArray
ますmatchedNames
。
の中に
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
私はこれらのコードを使用して動作させようとしましたが、それらの組み合わせを行っても何もしませんでした。
1)
if ([tableView isEqual: mentionTableView]){
NSLog(@"%@",matchedNames);
NSLog(@"%i",matchedNames.count);
return [matchedNames count];
} else if([tableView isEqual:forumTable]){
return [feedArray count];
}
2)
if (tableView == mentionTableView){
NSLog(@"%@",matchedNames);
NSLog(@"%i",matchedNames.count);
return [matchedNames count];
} else if(tableView == commentTable){
return [feedArray count];
}
3)
if (tableView.tag == 1){
NSLog(@"%@",matchedNames);
NSLog(@"%i",matchedNames.count);
return [matchedNames count];
} else if(tableView.tag == 2){
return [feedArray count];
}
する必要がないことはわかっていますが、else if
この問題を回避するために具体的にしようとしていました。
これは私のcellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.tag == 1){
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14);
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.transform = transform;
cell.textLabel.text = [self.matchedNames objectAtIndex:indexPath.row];
return cell;
} else {
static NSString *CellIdentifier = @"commentCell";
commentsCustomCell *cell =(commentsCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[commentsCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSDictionary *feedPost = [feedArray objectAtIndex:indexPath.row];
NSString *checkIFempty = [feedPost objectForKey:@"isForum_empty"];
if (![checkIFempty isEqualToString:@"1"]) {
cell.noCommentsLabel.text = nil;
} else {
cell.noCommentsLabel.text = @"No Comments";
cell.forumComment = nil;
}
NSString *username =[feedPost objectForKey:@"Username"];
NSString *final_time =[feedPost objectForKey:@"final_time"];
NSString *userIDforPic =[feedPost objectForKey:@"UserID"];
finalComment = [feedPost objectForKey:@"comment"];
cell.forumComment.text = finalComment;
return cell;
}
}
私の質問がわかりにくい場合は、申し訳ありませんが、36 時間寝ていません。私の質問を見てくれてありがとう!