我正在尝试编写一个简单的表格视图 > 详细应用程序以开始熟悉 obj-c。我使用字典来填充表格,而不是单击一个单元格,我会看到一个空白的详细信息视图。这项工作(我自豪地说)。当我尝试将信息发送到详细视图时,情况变得更糟,这是我得到的调试错误:
2012-07-12 14:32:41.906 StoryboardTutorial[79624:f803]-[UIView setText:]:无法识别的选择器发送到实例 0x6eae8d0
2012-07-12 14:32:41.908 StoryboardTutorial[79624:f803]由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIView setText:]:无法识别的选择器发送到实例 0x6eae8d0” *
* *First throw call stack: (0x13ca022 0x155bcd6 0x13cbcbd 0x1330ed0 0x1330cb2 0x2d41 0xdba1e 0xdbd11 0xed8fd 0xedaef 0xeddbb 0xee85f 0xeee06 0xc8a852d 0xeea24 0x27bd 0xa55c5 0xa57fa 0x93a85d 0x139e936 0x139e3d7 0x1301790 0x1300d84 0x1300c9b 0x12b37d8 0x12b388a 0x14626 0x1c4d 0x1bb5 0x1) terminate called throwing an exception(lldb)
这是一些代码块:
DetailViewController.h
// DetailViewController.h
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController{
NSString *city;
NSString *state;
IBOutlet UILabel *cityLabel;
IBOutlet UILabel *stateLabel;
}
@property (nonatomic,retain) NSString *city,*state;
@property (retain,nonatomic) IBOutlet UILabel *cityLabel,*stateLabel;
@end
细节视图控制器.m
// DetailViewController.m
#import "DetailViewController.h"
@implementation DetailViewController
@synthesize city,state,cityLabel,stateLabel;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
stateLabel.text = state;
cityLabel.text = city;
}
视图控制器.m
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"detail"];
detail.city = [dataSource objectAtIndex:indexPath.row];
detail.state = [states objectForKey:detail.city];
[self.navigationController pushViewController:detail animated:YES];
UITableViewCell *cell;
cell = [tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.shadowColor = [UIColor clearColor];
}
- (void)setupArray{
states = [[NSMutableDictionary alloc] init];
[states setObject:@"Roma" forKey:@"Lazio"];
[states setObject:@"Milano" forKey:@"Lombardia"];
dataSource = [states allKeys];
}