UIToolBar与UITableView - TableView加载时不刷新

问题描述:

UIToolBar有两个视图,一个UIView w/UITextViews和一个UIView w/UITableView。UIToolBar与UITableView - TableView加载时不刷新

通过UIToolBar调用的UITableView。 UITableView首次加载时,它会触击数据库并获取信息。我“选项卡”回到UIView瓦特/ UITextViews选择一些数据,然后“选项卡”回到UITableView,但没有委托方法被调用,如viewDidLoad或initWithNibName或任何东西,因此表中的数据是陈旧的。

所以,我发现了方法

-(void)viewWillAppear:(BOOL)animated { 

被调用,但是,它并没有进入的tableView,就好说了,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

我在此建议绊倒:

"I can't seem to figure out how to make the UITableView refresh ... I did find this, which seems like the same problem I'm having,

What I did is to create a MyTableViewController* property in MyModalViewController class. Before presentModalView, I store the table view controller pointer to this property in modal view controller.

Now I have a reference to table view controller when I'm in the modal view controller. Now just use this stored table view controller to locate its tableView, then reloadData.

Feels dirty but gets work done."

如果这就是答案,我不知道如何编码它。

谢谢!

  • SK

注:我只是尝试这样做:

.H

UITableView *tableViewPtr; 
@property (nonatomic, retain) UITableView *tableViewPtr; 

.M

@synthesize tableViewPtr; 

并将其存储在 -

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {: 
... 
self.tableViewPtr = tableView; 
... 

然后尝试从

-(void)viewWillAppear:(BOOL)animated { 
[self.tableViewPtr reloadData]; 

调用它,但是似乎并没有工作。

视图
+0

我试过这个以及: .h UITableView * tableViewPtr; @property(nonatomic,retain)UITableView * tableViewPtr; .m @synthesize tableViewPtr; (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {: ... self.tableViewPtr = tableView; ... 然后尝试从 - (void)viewWillAppear调用它:(BOOL)animated {: [self.tableViewPtr reloadData]; 但这似乎并不奏效。 – 2009-06-02 01:55:06

+0

好主,最后的评论是毁了。抱歉。 – 2009-06-02 01:55:23

将出现方法(我假设在你的控制器类)调用

[self.tableView reloadData]; 

感谢您的帮助。终于解决了,这里是问题:

1)我的控制器扩展UIViewController,而不是UITableViewController。

一旦我扩展了正确的类,然后通过文件所有者和IB正确连线,它就可以工作。现在在viewWillAppear我可以调用self.tableView reloadData。

永远不会再犯这个错误!

感谢所有 -

SK

您可以使用一个UIViewController - 你只需要实现的UITableViewDelegate和UITableViewDataSource协议。

--R

MR-SK:你可能需要了解一些关于的Objective-C是如何工作的。在声明的UIViewController(或子类),您只需执行的UITableView协议:

@interface ViewWithTableView : UIViewController 
    <UITableViewDelegate, UITableViewDataSource> {...} 

然后你实现你的viewController内所需的协议的方法。只有少数方法需要实现以支持tableView。

如果你使用IB,定义你的界面是这样的:

@interface ViewWithTableView : UIViewController 
    <UITableViewDelegate, UITableViewDataSource> { 
    IBOutlet UITableView *yourTableView; 
    . . . 
} 

,并保存它,然后去IB和对的tableView单击鼠标右键。从DataSource和Delegate中单击并拖动绑定到你的viewController(可能是你的文件所有者)。然后点击viewController并输入cmd-4。选择“ViewWithTableView”或任何您在类别标识部分的类别下拉菜单中调用它。保存一切,它会一切工作。

需要注意的是,除非你添加一个@property您的tableView,你不会叫自己,因为没有访问:

[yourTableView whatever:withWhatever]; 

与任何代码输入即兴,您的里程可能会有所不同。 :\