如何在xcode 4.6 ios6中运行我的表视图?

时间:2013-06-03 16:01:59

标签: ios xcode uitableview ios6 xcode4.6

我意识到有很多像我这样的帖子,但我仍然无法使代码正常工作。任何帮助将不胜感激。

我没有实现所有要实现的方法,所以不要担心这些。在我将tableview中的xib链接到数据源并委托后,错误就出现了。

如果我发布任何相关内容,请告诉我。

错误:

2013-06-03 10:57:16.814 WID Sign-in[7587:11303] -[UITableView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xb3b0800
2013-06-03 10:57:16.816 WID Sign-in[7587:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xb3b0800'
*** First throw call stack:
(0x1c94012 0x10d1e7e 0x1d1f4bd 0x1c83bbc 0x1c8394e 0x1fa548 0x1fd224 0xc1952 0xc12dc 0xc4dd6 0xc9a7e 0x662dd 0x10e56b0 0x2290fc0 0x228533c 0x2290eaf 0x1052bd 0x4db56 0x4c66f 0x4c589 0x4b7e4 0x4b61e 0x4c3d9 0x4f2d2 0xf999c 0x46574 0x4676f 0x46905 0x4f917 0x2cdb 0x13157 0x13747 0x1494b 0x25cb5 0x26beb 0x18698 0x1befdf9 0x1befad0 0x1c09bf5 0x1c09962 0x1c3abb6 0x1c39f44 0x1c39e1b 0x1417a 0x15ffc 0x291d 0x2845 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

·H:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>{
    NSMutableArray *existingNames;
    NSMutableArray *existingCompanies;
    NSMutableArray *currentNames;
    NSMutableArray *currentCompanies;
IBOutlet UITableView *preExisting;
}


@property (nonatomic, retain) NSMutableArray *existingNames;
@property (nonatomic, retain) NSMutableArray *existingCompanies;
@property (nonatomic, retain) NSMutableArray *currentNames;
@property (nonatomic, retain) NSMutableArray *currentCompanies;

@property (weak, nonatomic) IBOutlet UITextField *name;

@property (weak, nonatomic) IBOutlet UITextField *company;


- (IBAction)add:(id)sender;
- (IBAction)addExisting:(id)sender;

@end

的.m:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize name, company, existingNames, existingCompanies, currentNames, currentCompanies;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [existingCompanies count]; // <------- here there is the problem with iOS 5.1, also [array1 count]
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:
            UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
}

cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];

cell.textLabel.text = [NSString stringWithFormat:@" %@",[existingCompanies objectAtIndex:indexPath.row]];
cell.textLabel.font = [UIFont systemFontOfSize:13];
cell.textLabel.textColor = [UIColor blackColor];

return cell;
}


- (IBAction)add:(id)sender {
BOOL exists = [existingNames containsObject:name.text];

if(exists == FALSE){
    [existingNames addObject:name.text];
    [existingCompanies addObject:company.text];
}

[currentNames addObject:name.text];
[currentCompanies addObject:company.text];

name.text=@"";
company.text=@"";

// Set the delegate and datasource. Don't expect picker view to work
// correctly if you don't set it.

}

- (IBAction)addExisting:(id)sender {
}
@end

3 个答案:

答案 0 :(得分:3)

看起来您已经错误地连接了tableview数据源。

  

[UITableView tableView:numberOfRowsInSection:]:无法识别的选择器   发送到实例0xb3b0800'

这就是说框架试图在不符合tableView:numberOfRowsInSection协议的对象上调用UITableViewDataSource选择器。

答案 1 :(得分:3)

您似乎已将表格视图插座指定为数据源,而不是视图控制器。

将数据源更改为视图控制器,并且应正确调用该数据源方法。

答案 2 :(得分:0)

我没有正确启动我的NSMutableArrays以及在我的.h中声明它们,这是不必要的。感谢那些试图帮助的人!