我是 iOS 开发新手,因此对于提出可能愚蠢的问题深表歉意。
我想做的是与默认天气应用程序非常相似的事情;如果应用程序有一个信息按钮,它会翻转到另一个 View ,该 View 有一个表格和一个“完成”按钮,用于返回应用程序。
我正在使用“实用程序应用程序”模板,它为我完成了大部分工作:)
但是,我现在正在努力将表格 View 添加到翻转 View 中。我走在正确的道路上吗?我现在正在使用 Storyboard - 开始意识到这很可能是 GUI 的限制(毕竟 GUI 只能走这么远)。如果是这样,这是否可以通过编程方式实现,以及我将如何将其应用到默认的“实用程序应用程序”模板上。
我使用的是 Xcode 4.2。
如有任何帮助,我们将不胜感激。预先感谢:)
最佳答案
首先,您需要将 UITableView 拖放到界面构建器中的 flipsideViewController
上。确保您喜欢 View Controller 的委托(delegate)和数据源。
然后更改 flipsideViewController.h
为数组创建一个实例变量,该变量将存储单元格标签的文本,并使 Controller 符合表委托(delegate)和数据源方法。
@interface FlipsideViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
NSArray *myArrayOfItems;
}
在flipsideViewController.m
中alloc/init并在viewDidLoad
中填充数组
myArrayOfItems = [[NSArray alloc] initWithObjects:@"firstItem",@"secondItem",@"thirdItem",@"fourthItem", nil];
最后,复制并粘贴以下内容,您应该有一个工作表!
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [myArrayOfItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [myArrayOfItems objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Selected cell index:%i",indexPath.row);
}
关于iphone - Flipview 内的 Tableview 使用实用程序模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13076495/