【发布时间】:2013-10-12 05:33:45
【问题描述】:
我正在开发我的第一个应用程序,而且我是 Objective-C 的新手,我想做它,所以当有人输入 text field 然后按下按钮时,它会将其保存到 table view .有谁知道如何做到这一点或知道任何教程。
【问题讨论】:
标签: ios objective-c iphone tableview textfield
我正在开发我的第一个应用程序,而且我是 Objective-C 的新手,我想做它,所以当有人输入 text field 然后按下按钮时,它会将其保存到 table view .有谁知道如何做到这一点或知道任何教程。
【问题讨论】:
标签: ios objective-c iphone tableview textfield
您所要做的就是每次按下按钮时都会刷新/更新您的表格视图。
- (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;
}
如果您在使用 UITableView 配置时遇到问题,请参考 here。
【讨论】:
这些是给你的一些很好的教程..
http://www.appcoda.com/ios-programming-tutorial-create-a-simple-table-view-app/
http://www.codigator.com/tutorials/ios-uitableview-tutorial-for-beginners-part-1/
http://iosmadesimple.blogspot.in/2012/10/adding-uitableview-tutorial.html
编码愉快。
编辑:
这是我为你做的:
Simple Demo With TextField & TableView
编辑 2:
【讨论】:
BaseViewController 是我们用于常用方法的类。请注意。
storyboard 或 .xib 文件无关紧要。这只是逻辑。在这两种情况下都是一样的。只是推送和弹出页面是不同的。相信我,当您为某些客户开发应用程序时,您不会使用storyboard。因为使用它会太复杂。但是,如果您使用 .xib 文件,那么事情对您来说会容易得多。所以我认为我的回答是绝对正确的。