【问题标题】:Going from Table View to Different Detail Views in xcode在 xcode 中从表视​​图到不同的详细视图
【发布时间】:2011-05-21 01:49:57
【问题描述】:

我是一名初级程序员。我有一个问题。 我目前在我的应用程序中有一个表格视图。它分为三行,历史、理论和应用用途。我希望每个人都去不同的细节视图。但是,每个人都只点击其中一个详细视图。

我认为问题出在

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

【问题讨论】:

  • 这里有什么问题?

标签: ios xcode uitableview detailsview


【解决方案1】:
NSArray *array = [[NSArray alloc] initWithObjects:@"History", @"Theory", @"Applied Use", nil];

现在对 xibs 做同样的事情。创建数组并用 xib 名称填充它。然后在 didSelectRowAtIndexPath 中获取正确的 xib 名称,应用与在 cellForRowAtIndexPath 中相同的逻辑来获取单元格文本。

【讨论】:

  • 我将尝试一次迈出这一步,因为我对此很陌生:数组会像这样:xibArray *array = [[xibArray alloc] initWithObjects:@ “Magnets_History_Aubrey”,@“Magnets_Theory_Aubrey”,@“Magnets_AU_Aubrey”,无];在 NSArray 正下方的行中?
  • 我真的很困惑。我了解基本代码,但我仍然感到迷茫。请帮忙。这是一个学校项目,非常感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多