iPhone アプリを作成していますがTableView
、ボタンとボタンの追加に問題があります。次に示すように、通常のビューから始めて、テーブル ビューを追加し、上部にいくつかのボタンを追加しました。
問題は、アプリを実行すると次のようになることです。
追加したボタンはどちらもありません。ここに私の.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
誰かが私が間違っていることを教えてくれたら、それは素晴らしいことです。十分な情報を提供できていることを願っています。不足している場合はお知らせください。喜んで追加情報を提供いたします。