iPhone Dev: Reload data of a table view from a chi

2020-06-19 03:46发布

I'm implementing a notes manager application which has a tableView in a tabBar where the main information of its notes is displayed. When accessing to one note, you can edit its properties. In one button of the tabBar you can choose the way the notes are displayed in the tableView.

The problem I have is that I don't know how to reload the data from a child controller or from the other controller of the tabBar, either. I don't know how to refer to tableView from them so I can use reloadData to update the information of the TableView from them.

I'm quite new in iPhone development... any help will be really appreciated.

4条回答
混吃等死
2楼-- · 2020-06-19 03:54

the MVC pattern will help here,

as long as you keep updating your model with the information that is needed and your controllers are updating from that modal. As you flick back between the views you end up automatically updating the views.

that way you can call your reload data methods and they will get updated.

[tableviewController.tableview reloadData]; 

is how you access the reload data message.

查看更多
爷、活的狠高调
3楼-- · 2020-06-19 03:56

I came to the same problem while dealing with prototype cell. Weird I was quite sure I did everything right.

Then I started thinking if there's anything wrong with XCode. So I cleaned up everything, restarted XCode and it still complained.

At last, I tried to redo my most recent changes to the story board which is add a tableviewcell class and hooked it up with all my ui controls. Finally it stopped complaining.

I don't think this error is caused by your code or something, I've came to several weird errors in iOS 5. Right it's still testing and has lots of bugs.

Anyway, storyboard is great and I will try to get used to it, it draws the big picture of your app and is easy to handle the relationship between different views. Plus I really like his prepareforsegue method.

OK Good Luck.

查看更多
太酷不给撩
4楼-- · 2020-06-19 04:13

Put your table updating code in viewWillAppear: in stead of viewDidLoad - that way each time you go back to your parent controller from the child controller, the data get reloaded.

查看更多
够拽才男人
5楼-- · 2020-06-19 04:16

You should try NSNotificationCenter.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSomething:) name:@"doSomethingNotification" object:nil];

[[NSNotificationCenter defaultCenter] postNotificationName:@"doSomethingNotification" object:nil];
查看更多
登录 后发表回答