У меня есть текстовое поле, в котором пользователи вводят город, а также таблицу, чтобы заполнить города, которые пользователь выбирает. Однако, как только пользователь добавляет новый город, моя таблица не перезагружается, и по этой причине данные не обновляются в tableview. Я не знаю, чего мне не хватает. Я прикрепил свой код, а также скриншот.Перезагрузка TableView не работает
#import "AddCityViewController.h"
#import "ViewController.h"
@interface AddCityViewController()
@end
@implementation AddCityViewController
@synthesize addCityTF;
@synthesize myTableView;
@synthesize tableData;
@synthesize myString;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
tableData = [[NSMutableArray alloc] initWithCapacity:0];
[email protected]"Houston,London,Istanbul,Tokyo";
NSArray *array = [myString componentsSeparatedByString:@","];
tableData = [NSMutableArray arrayWithArray:array];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
NSLog(@"Data is :%@",[tableData objectAtIndex:indexPath.row]);
cell.textLabel.font = [UIFont fontWithName:@"BebasNeue" size:24];
return cell;
}
- (IBAction)addBtnClicked:(id)sender {
NSString* newString=[myString stringByAppendingString:addCityTF.text];
NSArray *array = [myString componentsSeparatedByString:@","];
tableData = [NSMutableArray arrayWithArray:array];
[myTableView reloadData];
//[self performSegueWithIdentifier:@"Main2Detail" sender:self];
}