开发者

UITableViewCell isn't accessible with standard method?

开发者 https://www.devze.com 2023-03-04 06:14 出处:网络
I\'m working on a project which has a controller, Controller, which holds all the logic (i.e. is the UITableViewDelegate). I have a view, View1 which is a subclasses UIView containing a UITableView as

I'm working on a project which has a controller, Controller, which holds all the logic (i.e. is the UITableViewDelegate). I have a view, View1 which is a subclasses UIView containing a UITableView as a property.

My problem is that I want to update the first row (which is some sort of a header-row) when something happens. I thought I could do this call:

UITableViewCell* headCell = 
    (UITableViewCell*) [view1.tableView 
        cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

but this doesn't seem to work. my headCell is (null) when I NSLog(@"%@", [headCell description]);

My controller calls [view1.tableView setDelegate:self], so I was also trying to call [self cellForRow..] but I just got unrecognized selector. The NSIndexPath should be correct, right?

I've tried to read up on this, but everyone seems to get cellForRowAtIndexPath to work, but I can't. Anyone got any ideas?

edit: I did a workaround instead, so can't really accept any answers without having tested them. Thanks though. The workaround was to create a cell that is referenced in开发者_Python百科 the cellForRowAtIndexPath:-method and tweak it manually somewhere else. I know it's not best practice, but I don't have time to do otherwise right now. Thanks for contributions though, I'll check in later to test them and accept as answers if I can get it to work :)


Use the NSNotification

See the apple doc for NSNotification

it will be added by your header row and post it anywhere from application with the required data .


cellForRowAtIndexPath method returns cell, if that cell is currently visible else it will return nil

0

精彩评论

暂无评论...
验证码 换一张
取 消