2012-09-22 33 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,更大的版本。我認爲你是對的,我需要改變行數來只顯示相關數組。 } –