viewDidAppear :
-(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)
{
self.commentTxt.text=@"";
[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];
}
答案 0 :(得分:2)
这是您需要在目标c
中解决的问题-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.tableData reloadData];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
dispatch_async(dispatch_get_main_queue(), ^(void){
//Run UI Updates
NSArray *paths = [self.tableData indexPathsForVisibleRows];
for (NSIndexPath *path in paths)
{
//get desired cell here
CustomCell *cell = (CustomCell *)[(UITableView *)self.view cellForRowAtIndexPath: path
];
cell.labeView //now you can update here on your cell items
}
});
});
}
这是我在 Swift
中的原始逻辑override func viewDidAppear(animated: Bool)
{
super.viewDidAppear(animated)
tableView.reloadData()
dispatch_async(dispatch_get_main_queue(), { () -> Void in
//get visible cells indexpaths
if let indices = self.tableView.indexPathsForVisibleRows
{
for index in indices
{
if index.section == 0 //this is specific to me, checking if section 0 is visible
{
//get desired cell here
let cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: 0,inSection: 0)) as! CustomCell
cell.myImageView.userInteractionEnabled = true //now i can update imageview on table cell
}
}
}
})
}
答案 1 :(得分:0)
在viewDidLoad
中Button buttonColor = new Button("Color");
buttonColor.setStyle("-fx-background-color: slateblue; -fx-text-fill: white;");
我希望它会有用。