2012-09-22 109 views
0

我在Xcode中开发了一个选项卡式应用程序。我遇到了一个并发症。Xcode IOS高级链接UITableView

我对我的进步感到满意,但在图2或场景2或SelectedCellViewController.m中,我不想看到像Pic1或Scene1下面的所有表格单元格。我只想看到一个表格单元格和相关表格单元格链接到图片3或场景3.

您可以在图片1或场景1中选择一个表格单元格,然后您可以看到您选择的颜色图片我会在图片下方加入一些信息。现在,您可以在Pic 2或Scene 2中看到图片下方有多个表格单元格。我只想显示相关表格单元,以便看到更大的版本,我已经编码了功能,但我很困惑如何摆脱Pic 2或Scene 2中的其他单元格。

我是不确定如何做到这一点,任何帮助将大大受到赞赏。

SelectcellViewController.h

@interface SelectedCellViewController : UIViewController { 
NSString *labelText; 
UIImage *banner; 
IBOutlet UILabel *label; 
IBOutlet UIImageView *imageView; 
IBOutlet UITableView *sampleViewDecors; 
UINavigationController *navigationController; 
NSArray *sitesArray; 
NSArray *bannerImages; 
} 

@property (nonatomic, copy) NSString *labelText; 
@property (nonatomic, retain) UIImage *banner; 
@property (nonatomic, retain) UITableView *sampleViewDecors; 
@property (nonatomic, retain) NSArray *sitesArray; 
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 
@property (nonatomic, retain) NSArray *bannerImages; 

@end 

viewControllerToShow.m

#import "SelectedCellViewController.h" 
#import "DetailViewController.h" 

@interface SelectedCellViewController() 

@end 

@implementation SelectedCellViewController 

@synthesize labelText; 
@synthesize banner; 
@synthesize sampleViewDecors; 
@synthesize sitesArray; 
@synthesize bannerImages; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { 
} 
return self; 
} 

- (void)didReceiveMemoryWarning { 
[super didReceiveMemoryWarning]; 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad { 


[super viewDidLoad]; 
[label setText:self.labelText]; 
[imageView setImage:self.banner]; 

// Load up the sitesArray with a dummy array : sites 
NSArray *sites = [[NSArray alloc] initWithObjects:@"Click here for a bigger view", @"b", @"c", @"d", @"e", @"f", @"g", @"h", nil]; 
self.sitesArray = sites; 
//[sites release]; 

/* Create the dummy banner images array and fill the main bannerImages array */ 

// Create the UIImage's from the images folder 
UIImage *app = [UIImage imageNamed:@"french.png"]; 
UIImage *creat = [UIImage imageNamed:@"Creattica.jpg"]; 
UIImage *free = [UIImage imageNamed:@"Freelance.jpg"]; 
UIImage *net = [UIImage imageNamed:@"Netsetter.jpg"]; 
UIImage *rock = [UIImage imageNamed:@"Rockable.jpg"]; 
UIImage *tuts = [UIImage imageNamed:@"Tutsplus.jpg"]; 
UIImage *work = [UIImage imageNamed:@"Workawesome.jpg"]; 

/* Create the dummy array and fill with the UIImages. */ 
NSArray *banners = [[NSArray alloc] initWithObjects:app, creat, free, net, rock, tuts, work, nil]; 

// Set the main images array equal to the dummy array 
self.bannerImages = banners; 





[super viewDidLoad]; 
} 

#pragma mark - Table View datasource methods 

// Required Methods 

// Return the number of rows in a section 
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section { 
return [sitesArray count]; 
} 

// Returns cell to render for each row 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellIdentifier = @"CellIdentifier"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
} 

// Configure cell 

NSUInteger row = [indexPath row]; 

// Sets the text for the cell 
cell.textLabel.text = [sitesArray objectAtIndex:row]; 

// Sets the imageview for the cell 
//cell.imageView.image = [imagesArray objectAtIndex:row]; 

// Sets the accessory for the cell 
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

// Sets the detailtext for the cell (subtitle) 
//cell.detailTextLabel.text = [NSString stringWithFormat:@"This is row: %i", row + 1]; 

return cell; 
} 

// Optional 

// Returns the number of section in a table view 
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { 
return 1; 
} 

#pragma mark - 
#pragma mark Table View delegate methods 

// Return the height for each cell 
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
return 78; 
} 

// Sets the title for header in the tableview 
//-(NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
// return @"Decors"; 
//} 

// Sets the title for footer 
//-(NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { 
// return @"Decors"; 
//} 

// Sets the indentation for rows 
-(NSInteger) tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath { 
return 0; 
} 


// Method that gets called from the "Done" button (From the @selector in the line - [viewControllerToShow.navigationItem setRightBarButtonItem:[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissView)] autorelease]];) 
- (void)dismissView { 
[self dismissViewControllerAnimated:YES completion:NULL]; 
} 

// This method is run when the user taps the row in the tableview 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
[tableView deselectRowAtIndexPath:indexPath animated:YES]; 

DetailViewController *detailviewControllerToShow = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]]; 
//[viewControllerToShow setLabelText:[NSString stringWithFormat:@"You selected cell: %d - %@", indexPath.row, [sitesArray objectAtIndex:indexPath.row]]]; 
detailviewControllerToShow.banner = [bannerImages objectAtIndex:indexPath.row]; 

[detailviewControllerToShow setModalPresentationStyle:UIModalPresentationFormSheet]; 
[detailviewControllerToShow setModalTransitionStyle:UIModalTransitionStylePartialCurl]; 
[detailviewControllerToShow.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissView)]]; 
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:detailviewControllerToShow]; 
detailviewControllerToShow = nil; 

[self presentViewController:navController animated:YES completion:NULL]; 
navController = nil; 

// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Tapped row!" 
//           message:[NSString stringWithFormat:@"You tapped: %@", [sitesArray objectAtIndex:indexPath.row]] 
//           delegate:nil 
//           cancelButtonTitle:@"Yes, I did!" 
//           otherButtonTitles:nil]; 
// [alert show]; 
// [alert release]; 

self.labelText = nil; 
self.banner = nil; 
//[label release]; 
// [imageView release]; 
[super viewDidUnload]; 


} 

- (void)viewDidUnload { 



} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 

enter image description here

回答

0

,因为在sitesArray值你的tableView有尽可能多的行。如果只有一个值,或者如果您更改了numberOfRowsInSection,则会得到一行表。

// Return the number of rows in a section 
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section { 
    return 1; 
} 
+0

我会怎样改变//返回的部分 行数 - (NSInteger的)的tableView:(UITableView的*)表numberOfRowsInSection:(NSInteger的)部分{ 回报1;只能在Pic2或Scene 2中显示相关的表格单元格。在Scene 2中,我需要显示相关的表格单元格。 EG如果你点击颜色梅花树,你会转到第二个地方你看到一个样本和一些信息,我想只能在场景2中显示梅花树的表格单元,所以点击时你会转到场景3,更大的版本。我认为你是对的,我需要改变行数来只显示相关数组。 } –