Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView停止滚动_Ios_Objective C_Uitableview_Scroll - Fatal编程技术网

Ios UITableView停止滚动

Ios UITableView停止滚动,ios,objective-c,uitableview,scroll,Ios,Objective C,Uitableview,Scroll,我的TableView使用自定义单元格,当我从DetailView返回时,它有时会“停止”滚动 我可以将视图向上推几英寸左右,下面的单元格确实可以进入视图,但滚动视图的高度应该是4或5个窗口 细节视图是通过一个segue调用的。除了后退按钮外,我还通过滑动手势触发返回。无论哪种情况都会发生但不是一直如此 希望这是足够的信息。有人知道我搞砸了什么吗? 谢谢 下面是一些代码: - (NSIndexPath *)tableView:(UITableView *)tableView willSelect

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

好的,所有的-在ViewWillAppease方法中,我尝试重新加载表,但没有任何影响。但我之前将contentSize重置为0,0,现在似乎工作正常,不完全确定原因-但我注意到第一次从detailview返回时,高度设置为2000左右,第二次返回时高度为零-在这一点上工作正常。所以我把它设为零,然后重新加载。
感谢Darren和所有人的回复

想象你是你的祖母(是的,她是)。现在再看一遍你的问题,告诉我们你是否真的明白了。如果你提供一些代码给她,会不会更有帮助?如果你给她提供了应用程序的屏幕截图,会不会更有帮助?听起来你的表视图的contentSize重置不正确。由于您使用的是自定义单元格,可能与tableView:heightForRowAtIndexPath:method有关。但是,您确实需要发布表视图控制器、数据源和委托的代码。请检查最明显的可能性。你说这“有时”会发生。也许tableview允许您正确地滚动到所有数据。添加一些日志记录并查看
numberOfSectionsInTableView:
tableView:numberofrowsinssection:
返回的内容。
- (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;
}