[英]Reload a tableView inside viewController
我在我的故事板上設置了一個viewcontroller,我在這個視圖控制器中插入了一個tableView。 我想做一個[self.tableView reloadData];
在viewDidLoad上,但它說找不到屬性tableView。
以下是viewcontroller.m文件中tableView的代碼如下所示:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return @"Shared with";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return activeUsers.count;
}
- (sharedUsersTable *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"sharedUser";
sharedUsersTable *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[sharedUsersTable alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *key = [activeUsers objectAtIndex:indexPath.row];
NSString *name = [key objectForKey:@"shared_user_name"];
NSString *email = [key objectForKey:@"email"];
cell.textLabel.text = [NSString stringWithFormat:@"%@", name];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", email];
return cell;
}
我是否缺少一些特殊的命令來調用一個不是TableViewCOntroller的視圖控制器中的tableView?
你需要創建一個tableView
的IBOutlet
並在其上調用reloadData
。
這取決於您如何聲明UITableView
。
如果它是一個屬性( @property (nonatomic, strong) UITableView *myTableView
[self.myTableView reloadData]
),它將是[self.myTableView reloadData]
。 如果您將其聲明為實例變量( UITableView *_myTableView
),則它將是[_myTableView reloadData]
。
你必須定義tableview數據源並委托為自己..如table.datasource=self
, table.delegate=self
.....你可以在viewdidload中執行....但是如果你已經在某處下載了數據,然后你可以在你下載的地方完成它並在那里重新加載表格。 請將委托和數據源分配給表,並在下載數據后重新加載tableview ....並且請創建類似(@property (nonatomic, strong) UITableView *table)
的屬性(@property (nonatomic, strong) UITableView *table)
並在重新加載時使用self。 ..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.