0

Xcode で Tabbed Style Application を開発しました。私は合併症に遭遇しました。

私は自分の進歩に満足していますが、Pic 2 または Scene 2 または SelectedCellViewController.m では、下の Pic1 または Scene1 のようにすべてのテーブル セルを表示したくありません。1 つのテーブル セルと関連するテーブル セルを表示して、Pic 3 または Scene 3 にリンクしたいだけです。

Pic 1 または Scene 1 で表のセルを選択すると、選択した色の写真が表示され、写真の下にいくつかの情報が含まれます。Pic 2 または Scene 2 で、写真の下に複数のテーブル セルがあることがわかります。関連するテーブル セルのみを表示したいので、より大きなバージョンが表示されます。機能は既にコーディングしていますが、Pic 2 またはシーン 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

ここに画像の説明を入力

4

1 に答える 1

0

tableView には、 にある値と同じ数の行がありますsitesArray。値が 1 つしかない場合、または を変更numberOfRowsInSectionすると、1 行のテーブルが得られます。

// Return the number of rows in a section
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
    return 1;
}
于 2012-09-22T20:39:58.697 に答える