Objective c UIViewController中的TableView

Objective c UIViewController中的TableView,objective-c,ios,uitableview,uiviewcontroller,xcode4.2,Objective C,Ios,Uitableview,Uiviewcontroller,Xcode4.2,我想在UIViewController中放置一个tableView,因为我需要在视图顶部放置一个工具栏,因此无法使用tableViewController。我已经创建了一个tableView类,并将我认为需要的函数放在其中,但我肯定遗漏了什么,或者放错了什么地方 h 您可能不想子类化UITableView。相反,在视图控制器子类中,声明您打算实现适当的委托和数据源协议: @interface MyViewController : UIViewController <UITableViewD

我想在UIViewController中放置一个tableView,因为我需要在视图顶部放置一个工具栏,因此无法使用tableViewController。我已经创建了一个tableView类,并将我认为需要的函数放在其中,但我肯定遗漏了什么,或者放错了什么地方

h


您可能不想子类化
UITableView
。相反,在视图控制器子类中,声明您打算实现适当的委托和数据源协议:

@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@接口MyViewController:UIViewController
然后,在视图控制器的实现文件中,实现上面定义的方法

最后,在Interface Builder中(或以编程方式)将表视图的
委托
数据源
出口设置为等于其superview的视图控制器(在IB中,此视图控制器是文件的所有者)


您还可以将数据数组设置为视图控制器的属性。

现在,我无法从tableView中的单元格或工具栏中的任何按钮中进行分隔。如果您谈论的是故事板分隔,我对它们不熟悉。另一方面,您当然可以使用
IBAction
s和
tableView:didSelectRowAtIndexPath:
delegate方法来实现您想要的任何功能。是否有机会获得此答案的更新版本?我正在尝试,但得到一个错误statin,您无法专门化非泛型类型UIViewController。。。
#import "TestTV.h"

@implementation TestTV
@synthesize arr = _arr;

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    _arr = [[NSArray alloc]initWithObjects:@"HEJ",@"FOO", nil];
    return _arr.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];
    }

    NSString *cellValue = [_arr objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;

    return cell;
}
@end
@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>