我的TableView使用自定义单元格,当我从DetailView返回时,有时会“停止”滚动。
我可以将视图向上推几英寸左右,下部单元格会进入视图,但是滚动视图应该是4或5个高度的窗口。
通过segue调用详细视图。除了后退按钮,我还会通过滑动手势触发返回。无论哪种方式都会发生。 - 不是所有的时间。
希望这是足够的信息。有没有人有任何想法我搞砸了? 谢谢!
以下是一些代码:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
int row = [indexPath row];
int sect = [indexPath section];
NSDictionary *shift = [globals.shifts objectAtIndex:sect];
NSLog(@"\nShift = %@", shift);
NSLog(@"\nEmployees = %@", [shift objectForKey:@"Employees"]);
NSArray *employees = [shift objectForKey:@"Employees"];
NSDictionary *employee = [employees objectAtIndex:row];
globals.badge = [employee objectForKey:@"Badge"];
globals.name = [employee objectForKey:@"Name"];
return indexPath;
}
- (void)receivedData:(NSData *)responseData {
NSError* error;
globals.report = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
globals.shifts = [globals.report objectForKey:@"shifts"];
[globals.ai removeFromSuperview];
[table reloadData];
self.title = [ [NSString alloc] initWithFormat:@"%@ - %@",
[globals.clientNames objectAtIndex:globals.curClient],
[self.dateFormatter stringFromDate: globals.weekEnd]];
self.title = [ [NSString alloc] initWithFormat:@"%@",
[self.dateFormatter stringFromDate: globals.weekEnd]];
}
-(void) viewWillAppear:(BOOL)animated {
if( globals == nil || globals.report == nil )
{
appDelegate = (MSIAppDelegate *)[[UIApplication sharedApplication] delegate];
globals = [appDelegate globals];
[[self view] addSubview:globals.ai];
NSString *urlString = [[NSString alloc] initWithFormat:
@"http://www.msiwebtrax.com/Client/%@/WeeklyReport?id=%@&start=%@&end=%@", [globals.clientIDs objectAtIndex:globals.curClient], globals.userName, [globals.formatter stringFromDate: globals.weekEnd], [globals.formatter stringFromDate: [globals.weekEnd dateByAddingTimeInterval:(-7) * 24 * 60 * 60] ]];
NSURL *url = [NSURL URLWithString: urlString];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
NSData* data = [NSData dataWithContentsOfURL:
url];
[self performSelectorOnMainThread:@selector(receivedData:)
withObject:data waitUntilDone:YES];
});
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *tempScrollView=(UIScrollView *)self.view;
NSLog(@"scroll view dimensions: %f, %f", tempScrollView.contentSize.height, tempScrollView.contentSize.width);
self.dateFormatter = [[NSDateFormatter alloc] init];
[self.dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[self.dateFormatter setTimeStyle:NSDateFormatterNoStyle];
// Uncomment the following line to preserve selection between presentations.
self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
这是部分/行的数量
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
int sections = [globals.shifts count];
return sections;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSDictionary* shift = [globals.shifts objectAtIndex:section];
int rowCount = [[shift objectForKey:@"Employees"] count];
return rowCount;
}
-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"EmployeeHoursCell";
EmployeeHoursCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if( cell == nil ) {
cell = [[EmployeeHoursCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
globals.employees = [[globals.shifts objectAtIndex:section] objectForKey:@"Employees"];
cell.Row.text = [[NSString alloc] initWithFormat:@"%3d", (row+1)];
cell.Id.text = [[globals.employees objectAtIndex:row] objectForKey:@"Badge"];
cell.Name.text = [[globals.employees objectAtIndex:row] objectForKey:@"Name"];
NSArray *days = [[globals.employees objectAtIndex:0] objectForKey:@"Days"];
cell.Hrs1.text = [[NSString alloc] initWithFormat:@"%@",[[days objectAtIndex:0] objectForKey:@"Rounded"] ];
cell.Hrs1.text = [[NSString alloc] initWithFormat:@"%.2f", [cell.Hrs1.text doubleValue]];
cell.Hrs2.text = [[NSString alloc] initWithFormat:@"%@",[[days objectAtIndex:1] objectForKey:@"Rounded"] ];
cell.Hrs2.text = [[NSString alloc] initWithFormat:@"%.2f", [cell.Hrs2.text doubleValue]];
cell.Hrs3.text = [[NSString alloc] initWithFormat:@"%@",[[days objectAtIndex:2] objectForKey:@"Rounded"] ];
cell.Hrs3.text = [[NSString alloc] initWithFormat:@"%.2f", [cell.Hrs3.text doubleValue]];
cell.Hrs4.text = [[NSString alloc] initWithFormat:@"%@",[[days objectAtIndex:3] objectForKey:@"Rounded"] ];
cell.Hrs4.text = [[NSString alloc] initWithFormat:@"%.2f", [cell.Hrs4.text doubleValue]];
cell.Hrs5.text = [[NSString alloc] initWithFormat:@"%@",[[days objectAtIndex:4] objectForKey:@"Rounded"] ];
cell.Hrs5.text = [[NSString alloc] initWithFormat:@"%.2f", [cell.Hrs5.text doubleValue]];
cell.Hrs6.text = [[NSString alloc] initWithFormat:@"%@",[[days objectAtIndex:5] objectForKey:@"Rounded"] ];
cell.Hrs6.text = [[NSString alloc] initWithFormat:@"%.2f", [cell.Hrs6.text doubleValue]];
cell.Hrs7.text = [[NSString alloc] initWithFormat:@"%@",[[days objectAtIndex:6] objectForKey:@"Rounded"] ];
cell.Hrs7.text = [[NSString alloc] initWithFormat:@"%.2f", [cell.Hrs7.text doubleValue]];
return cell;
}
好的 - 在viewWillAppear方法中,我尝试重新加载表,这没有任何影响。但我之前将contentSize重置为0,0现在似乎工作正常,不完全确定原因 - 但我注意到第一次从详细视图回来,高度设置为2000左右,第二次返回它是零 - 在这一点上它起作用。所以我把它设置为零并重新加载。 感谢Darren和所有回复!