我试图刷新一个UITableView
每次我浏览包含此表的视图时。UITableView刷新问题
我有一个ViewController
和一个自定义UITableViewController
,它管理在应用程序启动时使用包含在控制器内的NSMutableArray
正确设置表。
当我导航到包含该表的页面时,ViewController
调用一个函数,该函数从具有HTTP请求的服务器获取数据并在NSMutableArray
中解析它。
现在,这是我的问题。我设法将这个数组发送到我的UITableViewController
,但是当我想刷新我的tableView时,没有任何反应。
我试图使用[myTable reloadData]
,但它不调用numberOfRowsInSection或cellForRowAtIndexPath
函数。只见那人同样的问题,解决它使用[self.myTable ReloadData]
,但我得到一个错误:
访问未知的getter/setter方法
我非常新的目标-C,而这个错误是对我来说仍然有点神秘,因为我随意得到它。
无论如何,我很可能会对UITableViewController
(我应该在哪里声明它?)的声明和Interface Builder链接进行混乱,因此这可能是找到解决方案的线索。
任何人有一个想法?
非常感谢!
编辑:这里是我的tableview控制器类:
#import "MyCell.h"
@class Mycell;
@interface MyTableController : UITableViewController {
IBOutlet MyCell * myCell;
IBOutlet UITableView * myTable;
NSMutableArray *data;
}
@property (nonatomic, retain) IBOutlet UITableView * myTable;
- (void) EditTable : (NSMutableArray*) param;
@end
而现在的.M:
@implementation MyTableController
@synthesize myTable;
- (void) viewDidLoad {
[super viewDidLoad];
myTable = [[UITableView alloc] init];
data = [[NSMutableArray alloc] init];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MyCell";
MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; >
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (MyCell *) currentObject;
}
}
}
NSString *datastring = [listenom objectAtIndex:indexPath.row];
[cell setCell: datastring ];
return cell;
}
- (void) EditTable : (NSMutableArray*) param{
//This function is called by the ViewController when the user goes to the page containing the view
data = param; //The param array contains the data from the HTTP request
[self.tableView reloadData];
[self.myTable reloadData]; //I tried both, but only the first one actually calls the previous functions
}
欢迎这样的!我固定的代码的格式在您的文章,以便更容易为人们未来,“>”很好地突出显示一行代码,但要做一个块,您需要选择它并点击表格顶部的“{}”按钮。 – 2011-03-11 15:58:33
谢谢!当我看到我自己的消息时,我有点尴尬,我一定会在下次更正确地写我的代码。 – 2011-03-11 16:12:21
@Mathiew - 别担心,你应该看到我的第一篇文章! – 2011-03-11 17:29:18