2013-10-12 5 views
1

Я работаю над своим первым приложением, и я новичок в Objective-C, я хочу сделать это, когда кто-то набирает text field, а затем нажимает кнопку, он сохранит его до table view. Кто-нибудь знает, как это сделать или знать какие-либо учебники.Как сохранить данные из текстового поля в таблицу?

ответ

0
+0

есть ли способ сделать это с несколькими текстовыми полями, а текстовые поля находятся на другом представлении, чем в виде таблицы. – Jacobanks

+0

@JacobBanks, проверьте наличие новой демонстрации. –

+0

@JacobBanks, 'BaseViewController' - это класс, который мы используем для общих методов. Обратите внимание, что. –

1

все, что вам нужно сделать, это каждый раз, когда вы нажмите кнопку y ou'll обновит/обновит таблицу.

- (IBAction)buttonPressed:(id)sender { 
NSString *textNameToAdd = yourTextField.text; 
[containerArrayForTableView addObject:textNameToAdd]; 
[myTableView reloadData]; 
} 

// UITABLEVIEW DELEGATES 
- (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. 
// Usually the number of items in your array (the one that holds your list) 
return [containerArrayForTableView count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
//Where we configure the cell in each row 

static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell; 

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 
// Configure the cell... setting the text of our cell's label 
cell.textLabel.text = [containerArrayForTableView objectAtIndex:indexPath.row]; 
return cell; 
} 

см here, если у вас возникли проблемы с настраиваемым UITableView.

+0

Большое спасибо, но я действительно новичок, когда я положил это на мой взгляд, контроллер.mi получил 6 ошибок, мне нужно что-то положить в .h – Jacobanks

+0

Перейти к yout .h файл добавляет UITableViewDelegate, что-то вроде этого. @interface ViewController: UIViewController Bordz

+0

спасибо, это все. – Jacobanks

Смежные вопросы