도구 모음 (내 탐색 표시 줄 아래)과 tableview를 구현하는 데 문제가 있습니다. 내 스토리 보드에서 보통 ViewController
을 만든 다음 NavigationController
부분을 만든 다음 UIToolBar
과 UITableView
을 추가했습니다. 이 작업이 끝나면 ViewController
개의 파일을 만들었습니다. 그것은 모두 작동합니다. 그러나 툴바에서 버튼을 누르면 셀에 클릭으로 등록되므로 앱이 다운됩니다. 내 지식으로는이 문제를 해결할 수있을 정도로 충분하지 않기 때문에 여기에서 묻습니다.툴바와 TableView가 두통을 겪고 있습니다
또한 스크롤하면 도구 모음이 맨 위에 있지 않습니다. 테이블과 함께 스크롤합니다.
어떻게이 두 가지 문제를 해결할 수 있습니까?
#import "TableViewController.h"
#import "AFHTTPRequestOperationManager.h"
#import "UIImageView+AFNetworking.h"
#import "Ninja.h"
#import "DetailViewController.h"
#import "AMSlideMenuMainViewController.h"
#import "UIViewController+AMSlideMenu.h"
#import "UIImageView+WebCache.h"
#import "NSString+FontAwesome.h"
@interface TableViewController()
@property (nonatomic, strong)NSArray *ninjas;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *movies;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *shows;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *profile;
@property (weak, nonatomic) IBOutlet UIToolbar *mainToolBar;
@end
@implementation TableViewController
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setToolbarHidden:YES animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Your watched movies";
[self addRightMenuButton];
[self loadNinjas];
[self.movies setTitleTextAttributes:@{
NSFontAttributeName: [UIFont fontWithName:@"FontAwesome" size:24.0],
NSForegroundColorAttributeName: self.view.tintColor
} forState:UIControlStateNormal];
[self.movies setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-dot-circle-o"]];
[self.shows setTitleTextAttributes:@{
NSFontAttributeName: [UIFont fontWithName:@"FontAwesome" size:24.0],
NSForegroundColorAttributeName: self.view.tintColor
} forState:UIControlStateNormal];
[self.shows setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-pencil-square-o"]];
[self.profile setTitleTextAttributes:@{
NSFontAttributeName: [UIFont fontWithName:@"FontAwesome" size:24.0],
NSForegroundColorAttributeName: self.view.tintColor
} forState:UIControlStateNormal];
[self.profile setTitle:[NSString fontAwesomeIconStringForIconIdentifier:@"fa-plus"]];
self.mainToolBar.barTintColor = [UIColor whiteColor];
self.mainToolBar.layer.shadowColor = [[UIColor blackColor] CGColor];
self.mainToolBar.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);
self.mainToolBar.layer.shadowRadius = 3.0f;
self.mainToolBar.layer.shadowOpacity = 1.0f;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.ninjas.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.textLabel.text = [self.ninjas[indexPath.row] name];
NSString *imageUrl = [NSString stringWithFormat: @"%@", [self.ninjas[indexPath.row] thumbnail]];
[cell.imageView setImageWithURL:[NSURL URLWithString:imageUrl]
placeholderImage:[UIImage imageNamed:@"50-50.jpg"]];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50.0f;
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
DetailViewController *detailvc = [segue destinationViewController];
// Pass the selected object to the new view controller.
NSIndexPath *index = self.tableView.indexPathForSelectedRow;
Ninja *ninja = self.ninjas[index.row];
detailvc.ninja = ninja;
}
- (void)loadNinjas {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/movies"]];
NSMutableURLRequest *mutableRequest = [request mutableCopy];
request = [mutableRequest copy];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSArray *jsonArray = (NSArray *)[responseObject objectForKey:@"data"];
NSMutableArray *tempNinjas = [[NSMutableArray alloc] init];
for (NSDictionary *dic in jsonArray) {
Ninja *ninja = [[Ninja alloc] initWithDictionary:dic];
[tempNinjas addObject:ninja];
}
self.ninjas = [[NSArray alloc] initWithArray:tempNinjas];
tempNinjas = nil;
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Shows"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}];
[operation start];
}
@end
그리고이 스토리 보드 스크린 샷은이 : http://imgur.com/EOe9iQ3
스토리 보드의 화면 캡처 - 특히 오른쪽 보드 편집기 왼쪽의 장면에있는 객체 계층 구조를 표시 할 수 있습니까? – Paulw11
다음 페이지로 이동하십시오 : http://imgur.com/EOe9iQ3 – user4191537
툴바는 서브 뷰입니다 장면 목록에서 볼 수 있듯이 테이블보기 이외의 기본보기가없는 것 같습니다. UIViewController를 사용 했습니까? 컨트롤러의 기본보기를 아마도 삭제 했습니까? – rdelmar