gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:15:58 25 4
gpt4 key购买 nike

我正在创建一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com