![](/img/trans.png)
[英]Problem Adding UITabbar to Existing UITableView - iPhone SDK
[英]Iphone SDK - adding UITableView to UIView
我正在嘗試學習如何使用不同的視圖,對於此示例測試應用程序,我有一個登錄頁面,成功登錄后,用戶將被重定向到表格視圖,然后在表格視圖中選擇一項后,用戶指向顯示該項目詳細信息的第三頁。
第一頁工作正常,但是當我轉到第二頁時,出現問題,顯示的表沒有標題,並且我無法添加標題或工具欄或表本身以外的任何內容。 當我單擊該項目時,不用說什么也沒有發生。 也沒有錯誤。
我對編程很陌生,並且一直在Java上工作,但從來沒有在C上工作(盡管我對C有一些基本知識),而目標C對我來說是新的。
這是代碼。
-(IBAction) login {
RootViewController *rootViewController = [[RootViewController alloc] init];
if([username.text isEqualToString:@"test"]&&[password.text isEqualToString:@"test"]){
[window addSubview:[rootViewController view]];
[window makeKeyAndVisible];
}
else {
loginError.text = @"LOGIN ERROR";
[window addSubview:[viewController view]];
[window makeKeyAndVisible];
}
}
@interface RootViewController : UITableViewController {
IBOutlet NSMutableArray *views;
}
@property (nonatomic, retain) IBOutlet NSMutableArray * views;
- (void)viewDidLoad {
views = [ [NSMutableArray alloc] init];
OpportunityOne *opportunityOneController;
for (int i=1; i<=20; i++) {
opportunityOneController = [[OpportunityOne alloc] init];
opportunityOneController.title = [[NSString alloc] initWithFormat:@"Opportunity %i",i];
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
[[NSString alloc] initWithFormat:@"Opportunity %i",i], @ "title", opportunityOneController, @"controller", nil]];
self.title=@"GPS";
}
[super viewDidLoad];
}
- (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] autorelease];
}
// Configure the cell.
cell.textLabel.text = [[views objectAtIndex:indexPath.row] objectForKey:@"title"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *targetViewController = [[views objectAtIndex:indexPath.row] objectForKey:@"controller"];
[[self navigationController] pushViewController:targetViewController animated:YES];
}
哇,我發現很難發布代碼。 我為格式錯誤而道歉,但我無法超越此文本編輯器的格式規則。
謝謝莎詩
從基於導航的應用程序開始。 根據需要制作盡可能多的視圖控制器(上方3個)。 根據需要將視圖控制器從一個推入另一個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.