Scott Sherwood のこのチュートリアル ( http://www.scott-sherwood.com/ios-5-creating-a-custom-side-tabbar-using-storyboards-and-custom-segues/ ) に従って、サブビューを使用して他のビューにロードするカスタム タブ バー。すべてが美しく機能し、結果に非常に満足しています。ただし、「タブ ページ」の 1 つにテーブル ビューを追加してデータ ソースに接続すると、アプリがクラッシュします。
ARC を使用しており、ゾンビをオンにしているため、テーブル ビューの割り当てが解除されたインスタンスにメッセージが送信されたことがコンソールに表示されます。テーブルビューを保持する方法がわからないので、データが表示されます。これは私の 2 番目のアプリであり、ストーリーボードと高度なビュー コントローラーにはまだ慣れていません。私は何が欠けていますか?
これが私のカスタムタブビューコントローラーです:
CustomTabBarViewController.h
@interface CustomTabBarViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>{
}
@property(weak,nonatomic)UIViewController *currentViewController;
@property(weak,nonatomic)IBOutlet UIView *placeholder;
@property (weak, nonatomic) IBOutlet UIImageView *tabIndicator;
@property (weak, nonatomic) IBOutlet UIImageView *headerBacker1;
@property (weak, nonatomic) IBOutlet UIImageView *headerBacker2;
@end
CustomTabBarViewController.m
#import "CustomTabBarViewController.h"
@interface CustomTabBarViewController ()
@property (weak, nonatomic) IBOutlet UIView *buttons;
@end
@implementation CustomTabBarViewController
@synthesize currentViewController;
@synthesize placeholder;
@synthesize buttons;
@synthesize tabIndicator;
@synthesize headerBacker1;
@synthesize headerBacker2;
- (void)viewDidLoad
{
[super viewDidLoad];
[self performSegueWithIdentifier:@"ProductSegue" sender:[self.buttons.subviews objectAtIndex:0]];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setTabIndicator:nil];
[self setHeaderBacker1:nil];
[self setHeaderBacker2:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"ProductSegue"]
|| [segue.identifier isEqualToString:@"ContactSegue"]
|| [segue.identifier isEqualToString:@"CategoryPage"]){
if([segue.identifier isEqualToString:@"ContactSegue"]){
[UIView animateWithDuration:0.25f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{
[tabIndicator setCenter:CGPointMake(614, 108)];
[headerBacker1 setCenter:CGPointMake(1024, 48)];
[headerBacker2 setCenter:CGPointMake(1024, 789)];
} completion:nil];
}else{
[UIView animateWithDuration:0.25f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{
[tabIndicator setCenter:CGPointMake(499, 108)];
[headerBacker1 setCenter:CGPointMake(341, 48)];
[headerBacker2 setCenter:CGPointMake(341, 789)];
} completion:nil];
}
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
@end
そして、テーブル ビューを含むタブに読み込まれるページ: (注*: このページは、ストーリーボードでテーブル ビュー データ ソースおよびテーブル ビュー デリゲートとしてリンクされています)
ProductListViewController.h
#import <UIKit/UIKit.h>
@interface ProductListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) NSMutableArray *maTheData;
@end
ProductListViewController.m
#import "ProductListViewController.h"
@interface ProductListViewController ()
@end
@implementation ProductListViewController
@synthesize maTheData;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
//
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"viewDidLoad");
if (!maTheData) {
maTheData = [[NSMutableArray alloc] initWithObjects:@"Comets", @"Asteroids", @"Moons", nil];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [maTheData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"categoryTableCell"];
UILabel *lblName = (UILabel *)[cell viewWithTag:100];
[lblName setText:[maTheData objectAtIndex:[indexPath row]]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
return interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
@end
ご意見ありがとうございます。