1

我的 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;
}

好的 - 在 vi​​ewWillAppear 方法中,我尝试重新加载表,但没有任何影响。但是我之前将 contentSize 重置为 0,0,现在它似乎工作正常,不完全确定为什么 - 但我注意到我第一次从详细视图返回时,高度设置为 2000 左右,第二次返回它为零 - 在这一点上它起作用。所以我将它设置为零并重新加载。感谢达伦和所有人的回复!

4

0 回答 0