我的tableview細胞是沒有得到關於viewDidAppear :
的UILabel沒有得到更新
-(void)viewDidAppear:(BOOL)animated
{
[[ApiAccess getSharedInstance] setDelegate:self];
[[[SocektAccess getSharedInstance]getSocket]setDelegate:self];
[[[SocektAccess getSharedInstance]getSocket] reconnect];
_chatSocket =[[SocektAccess getSharedInstance]getSocket];
if(self.updateWill)
{
NSLog(@"viewDidAppear");
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.updateId inSection:0];
NSLog(@"Update Value: %d",self.updateValue);
NSLog(@"Update ID: %d",self.updateId);
TimelineTableViewCell *cell = (TimelineTableViewCell *)[self.tableData cellForRowAtIndexPath:indexPath];
WallPost *data = self.myObject[indexPath.row];
data.commentCount = self.updateValue;
[self.myObject replaceObjectAtIndex:indexPath.row withObject:data];
WallPost *data2 = self.myObject[indexPath.row];
NSLog(@": %d",data2.commentCount);
cell.commentLabel.text = @" ";
[self.tableData beginUpdates];
[self.tableData reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
[self.tableData reloadData];
[self.tableData endUpdates];
}
self.updateWill = NO;
}
的self.updateWill
更新是一個布爾值,而且已經從另一個類觸發:
if(self.responseAdd.responseStat.status)
{
[email protected]"";
[self getData];
TimelineViewController *t = (TimelineViewController *)self.navigationController.viewControllers[0];
t.updateWill = YES;
t.updateId = self.index;
t.updateValue =(int)self.response.responseData.count+1;
NSLog(@"response %d",(int)self.response.responseData.count);
}
正如你所看到的,我已經創建了我的Main類的一個對象,它是TimelineViewController並添加了updateWill和其他值需要的屬性。但細胞沒有重新加載! w 帽子我在這裏做錯了?
更新
(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TimelineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
self.counter = 0;
WallPost *data = self.myObject[indexPath.row];
cell.image.userInteractionEnabled = YES;
cell.image.tag = indexPath.row;
if(self.updateWill == YES)
{
NSLog(@"YES YES");
data.commentCount= (int)self.updateValue;
[self.tableData beginUpdates];
[self.tableData reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
[self.tableData reloadData];
[self.tableData endUpdates];
cell.commentLabel.text = [NSString stringWithFormat:@"%d comments",data.commentCount];
}
else
{
data.commentCount = (int)data.comments.count;
cell.commentLabel.text = [NSString stringWithFormat:@"%d comments",data.commentCount];
}
其實,事情是,你需要做的更新tableview的cellforrowindex方法內的東西委託,而不是視圖的生命週期方法。所以,確保你也一樣。 – Himanshu
我試過,但它沒有工作! @Himanshu – Fay007
更新你的cellforrowindex代碼可能有問題。 – Himanshu