2012-11-15 6 views
-4

RootViewController.h수정 didSelectRowAtIndexPath, IOS

#import <UIKit/UIKit.h> 

    @interface RootViewController : UITableViewController { 

NSMutableArray *petsArray; 
} 

    @property (nonatomic, strong) NSMutableArray *petsArray; 

    @end 

RootViewController.m

내가 storyboarded 프로젝트 에서 사용하지 못할 느릅 나무 문제가 didSelectRowAtIndexPath에 있다고 생각
#import "RootViewController.h" 
#import "PetsViewController.h" 

    @interface RootViewController() 

    @end 

    @implementation RootViewController 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
self = [super initWithStyle:style]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

petsArray = [[NSMutableArray alloc] init]; 
[petsArray addObject:@"Dog"]; 
[petsArray addObject:@"Cat"]; 
[petsArray addObject:@"Snake"]; 
[self setTitle:@"PETS !"]; 

// Uncomment the following line to preserve selection between presentations. 
// self.clearsSelectionOnViewWillAppear = NO; 

// Uncomment the following line to display an Edit button in the navigation bar for this  view controller. 
// self.navigationItem.rightBarButtonItem = self.editButtonItem; 
} 


- (void)viewDidUnload 
{ 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 

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

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
// Return the number of sections. 
return 1; 
} 

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

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

// Configure the cell... 
cell.textLabel.text = [petsArray objectAtIndex:indexPath.row]; 

return cell; 
} 


#pragma mark - Table view delegate 

- (무효) tableView : (UITableView *) tableView didSelectRowAtIndexPath : (NSIndexPath *) indexPath { PetsViewController * pets = [[PetsViewController alloc] initWithNibName : @ "PetsViewController"번들 전자 : 없음];

if ([[petsArray objectAtIndex:indexPath.row] isEqual:@"Dog"]) { 
    pets.petsInt = 0; 
    [pets setTitle:[petsArray objectAtIndex:indexPath.row]]; 
} 

if ([[petsArray objectAtIndex:indexPath.row] isEqual:@"Cat"]) { 
    pets.petsInt = 1; 
    [pets setTitle:[petsArray objectAtIndex:indexPath.row]]; 
} 

if ([[petsArray objectAtIndex:indexPath.row] isEqual:@"Snake"]) { 
    pets.petsInt = 2; 
    [pets setTitle:[petsArray objectAtIndex:indexPath.row]]; 
} 

[self.navigationController pushViewController:pets animated:YES]; 

} 

    @end 

내가 많은 방법을 시도하고 난 마침내 올바른 방법을 실현,하지만에만 작동

#import "PetsViewController.h" 

@interface PetsViewController() 

@end 

@implementation PetsViewController 
@synthesize petsInt; 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
self = [super initWithStyle:style]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (void)viewDidLoad 
{ 

[super viewDidLoad]; 

dogArray = [[NSMutableArray alloc] initWithObjects:@"HAF",@"hafo", @"hafinio", nil]; 
catArray = [[NSMutableArray alloc] initWithObjects:@"MYAU",@"myainio", @"mya lya lya", nil]; 
snakeArray = [[NSMutableArray alloc] initWithObjects:@"fshhhhh",@"fsssss", @"xrt", nil]; 



} 

- (void)viewDidUnload 
{ 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 

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

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 

// Return the number of sections. 
return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
// Return the number of rows in the section. 

if (petsInt == 0) return [dogArray count]; 
if (petsInt == 1) return [catArray count]; 
if (petsInt == 2) return [snakeArray count]; 

[self.tableView reloadData]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"PetsCell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

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

// Configure the cell... 
if (petsInt == 0) cell.textLabel.text = [dogArray objectAtIndex:indexPath.row]; 
if (petsInt == 1) cell.textLabel.text = [catArray objectAtIndex:indexPath.row]; 
if (petsInt == 2) cell.textLabel.text = [snakeArray objectAtIndex:indexPath.row]; 

[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 

return cell; 
} 



#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
// Navigation logic may go here. Create and push another view controller. 
/* 
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; 
// ... 
// Pass the selected object to the new view controller. 
[self.navigationController pushViewController:detailViewController animated:YES]; 
*/ 
} 

@end 

답변

0
[self performSegueWithIdentifier:@"SEGUE_NAME" sender:self]; 


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([[segue identifier] isEqualToString:@"SEGUE_NAME"]) { 
     PetsViewController *pets = [segue destinationViewController]; 

     [pets setPetsInt:0]; 
     [pets setTitle:@"Title"]; 
    } 
} 
+0

작동하지 않음 로드 @ "MYAU", @ "myainio", @ "mya lya lya" – AKA

0
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 
NSIndexPath *indexPath = self.tableView.indexPathForSelectedRow; 

if ([[gazel objectAtIndex:indexPath.row] isEqual:@"<էրեբունի> Օդանավակայան"]) { 
    KangarList *kang = [segue destinationViewController]; 
    kang.kangarInt = 0; 
    [kang setTitle:[gazel objectAtIndex:indexPath.row]]; 
} 

if ([[gazel objectAtIndex:indexPath.row] isEqual:@"<էրեբունի> Օդանավակայան"]) { 
    KangarList *kang = [segue destinationViewController]; 
    kang.kangarInt = 1; 
    [kang setTitle:[gazel objectAtIndex:indexPath.row]]; 
} 

if ([[gazel objectAtIndex:indexPath.row] isEqual:@"<էրեբունի> Օդանավակայան"]) { 
    KangarList *kang = [segue destinationViewController]; 
    kang.kangarInt = 2; 
    [kang setTitle:[gazel objectAtIndex:indexPath.row]]; 
} 

if ([[gazel objectAtIndex:indexPath.row] isEqual:@"<էրեբունի> Օդանավակայան"]) { 
    KangarList *kang = [segue destinationViewController]; 
    kang.kangarInt = 3; 
    [kang setTitle:[gazel objectAtIndex:indexPath.row]]; 
} 
} 

PetsViewController.h

#import <UIKit/UIKit.h> 

@interface PetsViewController : UITableViewController { 
NSMutableArray *dogArray; 
NSMutableArray *catArray; 
NSMutableArray *snakeArray; 
int petsInt; 
} 

@property int petsInt; 

@end 

PetsViewController.m 보기 아래에있을 때 메소드 객체를로드하면 할수 있답니다 하나 설명하지만 thise

gazel = [[NSMutableArray alloc] init]; 

Data *data = [[Data alloc] init]; 
data.title = @"<էրեբունի> Օդանավակայան"; 
data.subtitle = @"Հարաֆ Արևմտյան Թաղամաս"; 
data.photo = 1; 
[gazel addObject:data]; 

같은 것을 하세 경우는 내가 개 배열이 "hafinio, hafo"@ "HAF"@ 스토리 보드 부하를, 테이프, 그리고 때 고양이 배열 녹화 때 필요

관련 문제