Objective c 为什么赢了';我的UITableView显示器不可用吗?
我在这里搜索了stackoverflow,但没有找到解决方案 我期望发生的事情:UITableView以显示和显示包含“hi”的单元格 发生了什么:UITableView甚至不显示 ViewController.hObjective c 为什么赢了';我的UITableView显示器不可用吗?,objective-c,xcode,uitableview,Objective C,Xcode,Uitableview,我在这里搜索了stackoverflow,但没有找到解决方案 我期望发生的事情:UITableView以显示和显示包含“hi”的单元格 发生了什么:UITableView甚至不显示 ViewController.h 请告诉我我做错了什么,并更正我的代码 尝试将UITableViewController子类化而不是UIViewController。尝试将UITableViewController子类化而不是UIViewController。不清楚将UITableView连接到实例变量是什么意思。如
请告诉我我做错了什么,并更正我的代码 尝试将UITableViewController子类化而不是UIViewController。尝试将UITableViewController子类化而不是UIViewController。不清楚将UITableView连接到实例变量是什么意思。如果您的意思是从XIB连接起来,那么您可能会从您创建的被重写的getter方法中得到“干扰”。您可能需要放置一个NSlog,以查看是否正在调用该方法。如果是这种情况,那么您要分配/邀请的新表视图的框架大小为零,并且我在代码中没有看到您更改框架大小的任何地方
祝你好运 不清楚将UITableView连接到实例变量是什么意思。如果您的意思是从XIB连接起来,那么您可能会从您创建的被重写的getter方法中得到“干扰”。您可能需要放置一个NSlog,以查看是否正在调用该方法。如果是这种情况,那么您要分配/邀请的新表视图的框架大小为零,并且我在代码中没有看到您更改框架大小的任何地方 祝你好运
委托
和数据源
属性从表格视图
连接到文件的所有者委托
和数据源
属性从表格视图
连接到文件的所有者解释一下?我没有UITableViewController。我在UIViewController中有一个UITableView,因为它有利于我所做的事情。对此表示抱歉。如果您需要使用UIViewController而不是UITableViewController,那么我认为Tomasz的答案是正确的。正如Tomasz所说,您需要成为UITableViewDelegate和UITableViewDataSource的代表。解释一下?我没有UITableViewController。我在UIViewController中有一个UITableView,因为它有利于我所做的事情。对此表示抱歉。如果您需要使用UIViewController而不是UITableViewController,那么我认为Tomasz的答案是正确的。正如Tomasz所说,您需要成为UITableViewDelegate和UITableViewDataSource的代表。我在
-(UITableView*)tableView之后做了一个NSLog{
但它没有被调用。我该怎么办?然后您将希望遵循tomasz wojtkowiak的建议,并确保实现各种UITableView协议和数据源方法。我在-(UITableView*)tableView之后立即执行了NSLog{
它没有被调用。我该怎么办?然后你会想按照tomasz wojtkowiak的建议,确保你实现了各种UITableView协议和数据源方法。你说的文件所有者是什么意思?对不起,我在这方面有点陌生。另外,如果有帮助的话,我正在使用故事板。@blake305他指的是要实现的人输入协议方法,即代理,在您的情况下,它是viewViewController。如果您无法使用故事板连接代理,请在viewViewController的viewDidLoad
中,只需执行\u tableView.delegate=self
和\u tableView.dataSource=self
——假设您将协议包括在hea中der:@interface viewcontroller:UIViewController
如果你使用序列图像板,你应该将此属性连接到viewcontroller
。你说的文件所有者是什么意思?对不起,我在这方面有点陌生。另外,如果有帮助的话,我正在使用序列图像板。@blake305他指的是要实现协议方法的人,即delegate,在您的情况下,它是viewViewController。如果您无法使用故事板连接代理,则在viewViewController的viewDidLoad
中,只需执行\u tableView.delegate=self
和\u tableView.dataSource=self
-假设您在标题中包含了协议:@interface viewcontroller:UIViewController
如果使用故事板,则应将此属性连接到viewcontroller
。
#import <UIKit/UIKit.h>
@interface viewViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITableView *tableView;
//note: the above property is connected to my UITableViewController
@end
#import "viewViewController.h"
@interface viewViewController ()
@end
@implementation viewViewController
@synthesize tableView = _tableView;
- (UITableView *)tableView
{
if (!_tableView){
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
}
return _tableView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//_tableView = [[UITableView alloc] init];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
//[self setTableView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//warning Potentially incomplete method implementation.
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"asking for rows");
//#warning Incomplete method implementation.
// Return the number of rows in the section.
switch (section)
{
case 0:
return 5;
case 1:
return 10;
break;
default:
return 0;
break;
}
}
- (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.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = @"hi";
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"testtext";
}
@end