Doo*_*Man 5 objective-c uitableview ios
我的应用程序中有一个奇怪的错误,它使用侧边栏菜单和一个UITableView列表按钮进行导航。当我启动我的应用程序时,一切看起来都很好并且在正确的位置。
一旦我对相应的viewController, and navigate back to sidebar menu theUITableView`进行了选择,就会向下移动大约 1 英寸。
如果我按下侧边栏菜单按钮将其关闭,菜单会重置并且一切正常且看起来正常。这个错误只发生一次,一旦我选择一行,导航回它,关闭它,UITableView它将处于正确的位置,直到用户重新启动应用程序。知道发生了什么吗?
这是我的侧边栏菜单代码:
#import "SideBarViewController.h"
@interface SideBarViewController ()
@end
@implementation SideBarViewController
@synthesize controllerArray, sidebarButton;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
controllerArray = [NSArray arrayWithObjects:@"Search For Games", @"Login", @"Library", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [controllerArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [controllerArray objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *selection;
if (indexPath.row == 0) {
selection = [self.storyboard instantiateViewControllerWithIdentifier:@"SearchController"];
[self.navigationController pushViewController:selection animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
else if (indexPath.row == 1) {
selection = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginController"];
[self.navigationController pushViewController:selection animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
else if (indexPath.row == 2) {
selection = [self.storyboard instantiateViewControllerWithIdentifier:@"LibraryController"];
[self.navigationController pushViewController:selection animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
我按照“ Ray Wenderlich ”网站上的教程获取侧边栏代码。
另外,我测试了其他对象,例如按钮和标签,它们不会移动,只是UITableView会移动。
谢谢!
| 归档时间: |
|
| 查看次数: |
2965 次 |
| 最近记录: |