2011-05-21 32 views
0

我是一個開始的程序員。我有一個問題。 我目前在我的應用程序中有一個表視圖。有三行,歷史,理論和應用使用。我希望每個人都去一個不同的細節視圖。但是,每個人只能點擊一個詳細視圖。從表視圖到xcode中的不同細節視圖

我認爲這個問題是在

didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"Magnets_AU_Aubrey" bundle:[ 

請任何幫助。這三個XIB的是Magnets_AU_Aubrey,Magnets_History_Aubrey和Magnets_Theory_Aubrey

#import "DisclosureButtonController.h" 
#import "NavAppDelegate.h" 
#import "DisclosureDetailController.h" 
#import "DetailViewController.h" 

@implementation DisclosureButtonController 
@synthesize list; 

- (void)viewDidLoad { 
    NSArray *array = [[NSArray alloc] initWithObjects:@"History", @"Theory", @"Applied Use", nil]; 
    self.list = array; 
    [array release]; 
    [super viewDidLoad]; 
} 

- (void)viewDidUnload { 
    self.list = nil; 
    [childController release], childController = nil; 
} 

- (void)dealloc { 
    [list release]; 
    [childController release]; 
    [super dealloc]; 
} 

#pragma mark - 
#pragma mark Table Data Source Methods 
- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section { 
    return [list count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString * DisclosureButtonCellIdentifier = 
    @"DisclosureButtonCellIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: 
          DisclosureButtonCellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] 
       initWithStyle:UITableViewCellStyleDefault 
       reuseIdentifier:DisclosureButtonCellIdentifier] autorelease]; 
    } 
    NSUInteger row = [indexPath row]; 
    NSString *rowString = [list objectAtIndex:row]; 
    cell.textLabel.text = rowString; 
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
    [rowString release]; 
    return cell; 
} 

#pragma mark - 
#pragma mark Table Delegate Methods 
- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"Magnets_AU_Aubrey" bundle:[ 
                              NSBundle mainBundle]]; 
    [self.navigationController pushViewController:dvController animated:YES]; 
    [dvController release]; 
    dvController = nil; 
    } 



- (void)tableView:(UITableView *)tableView 

accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { 
    if (childController == nil) { 
     childController = [[DisclosureDetailController alloc] initWithNibName:@"MagnetsAubreyCreditsDisclosureDetail" bundle:nil]; 
    } 
    childController.title = @"Disclosure Button Pressed"; 
    NSUInteger row = [indexPath row]; 
    NSString *selectedMovie = [list objectAtIndex:row]; 
    NSString *detailMessage = [[NSString alloc] 
           initWithFormat:@"School",selectedMovie]; 
    childController.message = detailMessage; 
    childController.title = selectedMovie; 
    [detailMessage release]; 
    [self.navigationController pushViewController:childController animated:YES]; 
} 

@end 
+0

這裏有什麼問題? – 2011-05-21 02:34:39

回答

0
NSArray *array = [[NSArray alloc] initWithObjects:@"History", @"Theory", @"Applied Use", nil]; 

現在做同樣xibs。創建數組並用xib名稱填充它。然後在didSelectRowAtIndexPath中獲取正確的xib名稱,應用與您在cellForRowAtIndexPath中獲取單元格文本相同的邏輯。

+0

我將嘗試一次採取這一步,因爲我很新:數組看起來像這樣:\t xibArray * array = [[xibArray alloc] initWithObjects:@「Magnets_History_Aubrey」,@「 Magnets_Theory_Aubrey「,@」Magnets_AU_Aubrey「,無];在NSArray下面的行中? – Parker 2011-05-21 07:14:23

+0

您應該閱讀本文檔作爲第一步:http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjectiveC/ObjC.pdf – TheBlack 2011-05-21 14:44:09

+0

我真的很困惑。我瞭解基本的代碼,但我仍然感到失落。請幫忙。這是一個學校項目,並會非常感謝幫助。 – Parker 2011-05-22 01:05:06

相關問題