我正在使用表格视图来显示不同的联系信息,根据您选择的那个,将会有该特定资源的详细信息。我有代码工作,但我移动了项目,所以我不确定为什么我的标签没有出现。我有一个状态联系人列表,然后你推一个导致细节。这是我的代码:
StateContacts.h
#import <UIKit/UIKit.h>
@interface StateContacts : UITableViewController <UITableViewDelegate,
UITableViewDataSource>
@property (nonatomic, strong) IBOutlet UITableView *tableView;
@end
StateContacts.m
#import "StateContacts.h"
#import "State.h"
@interface StateContacts ()
@end
@implementation StateContacts
{
NSArray *state;
NSArray *num;
NSArray *fax;
}
@synthesize tableView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Initialize table data
state = [NSArray arrayWithObjects:@"Child Abuse Hotline", @"Drug Lab Remediation", @"Prevent Suicide TN", @"TN Crime Vict. Comp.", @"TN Department of Education", @"TN Homeland Security", @"TN State Police", @"TN Supreme Court", nil];
num = [NSArray arrayWithObjects:@"(111) 111-1111", @"(222) 222-2222", @"(333) 333-3333", @"(444) 444-4444", @"(555) 555-5555", @"(666) 666-6666", @"(777) 777-7777", @"(888) 888-8888", nil];
fax = [NSArray arrayWithObjects:@"n/a", @"n/a", @"n/a", @"n/a", @"n/a", @"n/a", @"n/a", @"n/a", nil];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [state count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"myCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [state objectAtIndex:indexPath.row];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showStateInfo"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
State *destViewController = segue.destinationViewController;
destViewController.stateName = [state objectAtIndex:indexPath.row];
destViewController.pName = [num objectAtIndex:indexPath.row];
destViewController.fName = [fax objectAtIndex:indexPath.row];
}
}
@end
State.h
#import <UIKit/UIKit.h>
@interface State : UIViewController
@property (nonatomic, strong) IBOutlet UILabel *stateLabel;
@property (nonatomic, strong) IBOutlet UILabel *pNumber;
@property (nonatomic, strong) IBOutlet UILabel *fNumber;
@property (nonatomic, strong) NSString *stateName;
@property (nonatomic, strong) NSString *pName;
@property (nonatomic, strong) NSString *fName;
@end
State.m
#import "State.h"
@interface State ()
@end
@implementation State
@synthesize stateLabel;
@synthesize stateName;
@synthesize pNumber;
@synthesize fNumber;
@synthesize pName;
@synthesize fName;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Set the Label text
stateLabel.text = stateName;
//number and fax in array
pNumber.text = pName;
fNumber.text = fName;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
我知道很多人以前都遇到过这个问题,我已经尝试了他们的建议,例如确保segue正确连接以及清理和重建。标签仍然没有出现。我的层次结构与UIView是正确的。 Here是我的故事板以及状态详细信息和StateContacts的连接。我只是不知道还有什么可以尝试。
答案 0 :(得分:1)
您的代码错误地定义了一个tableView
属性,该属性隐藏了从UITableView继承的原始tableView
属性。要解决此问题,只需删除属性和相应的@synthesize
指令即可。在您熟悉它的同时,您还可以删除State类中的@synthesize
指令,因为编译器现在默认自动合成属性。
请注意,一旦删除了冗余插座,您可能需要在Interface Builder中重新连接它,因此请务必仔细检查。