gpt4 book ai didi

ios - 如何让 xcode 4.6 ios6 中的 TableView 正常工作?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:17:54 25 4
gpt4 key购买 nike

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

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

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

错误:

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

最佳答案

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

[UITableView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xb3b0800'

这表示框架试图在不符合 UITableViewDataSource 协议(protocol)的对象上调用 tableView:numberOfRowsInSection 选择器。

关于ios - 如何让 xcode 4.6 ios6 中的 TableView 正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16901021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com