我想創建一個segue,以便在我的項目中的tableviewcontroller和視圖控制器之間建立鏈接。但是,當我運行這些應用程序時,當我單擊表格單元格時它沒有任何反應。無法將數據從tableview傳遞到視圖控制器
這裏是我的代碼:
#import "TableViewController.h"
#import "SimpleTableCell.h"
#import "ViewController2.h"
@interface TableViewController()
@end
@implementation TableViewController
{
NSArray *tableData;
NSArray *thumbnails;
NSArray *detail;
}
@synthesize tableview;
- (void)viewDidLoad {
[super viewDidLoad];
NSString*path = [[NSBundle mainBundle]pathForResource:@"LawFirm"ofType:@"plist"];
NSDictionary*dict= [[NSDictionary alloc] initWithContentsOfFile:path];
tableData=[dict objectForKey:@"Name"];
thumbnails=[dict objectForKey:@"Thumbnail"];
detail=[dict objectForKey:@"Detail"];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
UIEdgeInsets inset = UIEdgeInsetsMake(5, 5, 5, 5);
self.tableView.contentInset = inset;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [tableData count];
}
- (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
NSInteger rowIndex = indexPath.row;
UIImage *background = nil;
if (rowIndex == 0) {
background = [UIImage imageNamed:@"cell_top.png"];
} else if (rowIndex == rowCount - 1) {
background = [UIImage imageNamed:@"cell_bottom.png"];
} else {
background = [UIImage imageNamed:@"cell_middle.png"];
}
return background;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
SimpleTableCell *cell = (SimpleTableCell*) [tableView dequeueReusableCellWithIdentifier: simpleTableIdentifier];
if (cell == nil) {
NSArray*nib = [[NSBundle mainBundle]loadNibNamed:@"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.name.text = [tableData objectAtIndex:indexPath.row];
cell.photo.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
cell.detail.text = [detail objectAtIndex:indexPath.row];
UIImage*background = [self cellBackgroundForRowAtIndexPath:indexPath];
UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
cellBackgroundView.image = background;
cell.backgroundView = cellBackgroundView;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 78;
}
-(void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"showlawfirmdetail"]){
NSIndexPath*indexPath = [self.tableView indexPathForSelectedRow];
ViewController2*vc = segue.destinationViewController;
vc.lawfirmname = [thumbnails objectAtIndex:indexPath.row];
}
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
@end
我已經加入導航控制器和實現代碼如下控制器之間增加SEGUE查看控制器。
任何人都可以幫助我嗎?
謝謝,但它似乎是:對「TableViewController」不可見@interface聲明選擇「performSegueWithIdentifier:」 –
我已經編輯我的答案,發送者失蹤:) – KIDdAe