iphone - iOS App 中的按钮不会显示

标签 iphone objective-c ios tableview

我正在创建一个 iPhone 应用程序,但在使用 TableView 时遇到了一些问题并添加按钮。我从常规 View 开始,然后添加了一个表格 View ,然后在顶部添加了几个按钮,如下所示:

TableViewImage

问题是,当我运行应用程序时,我得到了这个:

enter image description here

我添加的两个按钮都不存在。这是我的 .h 文件:

    //
//  RootBeerTVCViewController.h
//  BaseApp
//
//  Created by Blaine Anderson on 10/12/12.
//  Copyright (c) 2012 UIEvolution, Inc. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface RootBeerTVCViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>



@property (weak, nonatomic) IBOutlet UIButton *nameButton;
@property (weak, nonatomic) IBOutlet UIButton *locationButton;
@property(strong, nonatomic) NSMutableArray* rootList; 



-(IBAction)sort:(id)sender;

@end

这是 .M 文件:
//
//  RootBeerTVCViewController.m
//  BaseApp
//
//  Created by Blaine Anderson on 10/12/12.
//  Copyright (c) 2012 UIEvolution, Inc. All rights reserved.
//

#import "RootBeerTVCViewController.h"
#import "GlobalData.h"

@interface RootBeerTVCViewController ()


@end

@implementation RootBeerTVCViewController
@synthesize rootList; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization


    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    [GlobalData sharedData].mViewManager.mNavController.navigationBarHidden=NO;

    // Do any additional setup after loading the view from its nib.
    rootList = [[GlobalData sharedData] mRootList ];
     NSLog(@"RootList in view did load: %@", rootList);
    UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];

    tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;

    tableView.delegate = self;

    tableView.dataSource = self;

    //[tableView addSubview:sortingView]; 

    [tableView reloadData];

    self.view = tableView;
}

- (void)viewDidUnload
{

    [self setLocationButton:nil];
    [self setNameButton:nil];
    [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
{
    rootList = [[GlobalData sharedData] mRootList ];
    NSLog(@"RootList: %@", rootList);
    // Return the number of sections.
    NSLog(@"RootList count: %i", rootList.count);
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of sections.
    NSLog(@"RootList row count: %i", rootList.count);
    return rootList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    rootList =[[GlobalData sharedData].mRootBeerParser rootBeerList];
    NSLog(@"RootList Cell: %@", rootList);
    RootBeers* mRootBeer = [rootList objectAtIndex:indexPath.row];


    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle  reuseIdentifier:@"Cell"]; 
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    NSLog(@"Cell Name: %@", mRootBeer.brewer);
    // Configure the cell...
    cell.textLabel.text = mRootBeer.name; 
    cell.detailTextLabel.text = mRootBeer.location; 



    return cell;
}

/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
 {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
 }   
 else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }   
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
 {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


    RootBeers* mRootBeer =[rootList objectAtIndex:indexPath.row]; 
    [GlobalData sharedData].mRootBeer = mRootBeer; 
    [[GlobalData sharedData].mViewManager pushView:DETAILVIEW animated:YES]; 



}

- (IBAction)sort:(id)sender {

    rootList =[[GlobalData sharedData].mRootBeerParser rootBeerList];


    [[GlobalData sharedData].mRootBeerParser sortRootBeerByName:rootList]; 
}
@end

如果有人能让我知道我做错了什么,那就太好了。我希望我已经提供了足够的信息,如果没有,请告诉我,我很乐意提供更多信息。

最佳答案

在您的 viewDidLoad你创建一个新的UITableView屏幕大小,然后将其设置为 VC View ,从而覆盖从 xib 加载的 View 。因此,您只能看到您在代码中创建的表。

关于iphone - iOS App 中的按钮不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13328128/

相关文章:

objective-c - 如何构建一个 Objective-C 静态库?

ios - NSHashTable 保留弱引用

iphone - 在 Objective-C 中比较颜色

iphone - 来自 NSData 的图像未正确加载

ios - 如何从终端或使用任何Monkeytalk命令打开iPhone应用程序?

iphone - 如何获得 objective-c 中两个位置之间的距离(以英里为单位)?

iphone - 获取地址簿数据,它的代码在模拟器上运行但没有运行 iPhone 设备。

ios - CloudKit 订阅和 UNNotificationServiceExtension

ios - UITableView 异步图像加载 - 滚动之前不布局

iphone - iAD 被 UITableView 索引遮挡