【发布时间】:2014-02-19 07:25:54
【问题描述】:
请原谅我对 iPhone 编程的无知,因为我是它的新手。 我正在制作一个应用程序,其中初始化视图控制器是用于显示数据的 UITable 视图控制器和用于输入数据的另一个视图控制器。
我的问题是当我输入新数据时,它不会出现在 UItable 控制器中,我尝试在 viewDidLoad 中使用 [self.tableview reloadData] 重新加载数据,但数据不会重新加载,因为我使用的是自定义委托 我尝试将[self.tableview reloadData] 作为我的自定义委托的最后一行,但它也不起作用,我尝试使用viewDidAppear,但这也不起作用。
代码如下:
MainViewController.m (TableView)
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Initializing conference array");
conferenceData = [[NSMutableArray alloc]init];
SavingData *loadData = [[SavingData alloc]init];
NSLog(@"Loading the file then fill it in an array");
conferenceData = [loadData LoadDataArray];
NSLog(@"Done Initializing conference array");
[self.tableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [conferenceData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSLog(@"writing data in cell number %i",indexPath.row);
cell.textLabel.text = [[conferenceData objectAtIndex:indexPath.row]name];
return cell;
}
// Implementing the adding delegate
-(void) setInformation:(Adding *)controller withObject:(Conference *)info
{
Conference *confer = info; //Temprory Conference object to store data
SavingData *saveToFile = [[SavingData alloc]init];
if ([saveToFile SavingDataWithObject:confer]) //Calling SavingDataWithObject method and check if the save operation return true or false
{
NSLog(@"Done Saving !!");
}
[self.navigationController popToRootViewControllerAnimated:YES]; // after saving return to the main window
NSLog(@"Should be popped right now");
}
非常感谢您
【问题讨论】:
标签: objective-c uitableview ios7 xcode5 reloaddata