重新加载tableview的活动单元格(Reloading Active cells of tableview)
我正在开发iOS iOS 7.0及更高版本的应用程序。 现在,我的问题是如何重新加载屏幕上可见的UITableView行。 我正在使用动态细胞。
实际上在选择一个选项时,我正在改变一些颜色,比如每个单元格的标题颜色,但是那些已经加载到屏幕上的单元格没有改变,如果我正在加载整个表格,那么它需要很长时间。
等待您的回复。
码
//点击此按钮颜色正在更新
- (IBAction)btnDone:(id)sender { appDel.selectedMood=_moodDetView.str; appDel.barColor=_moodDetView.backgroundColor; self.navigationController.navigationBar.barTintColor = _moodDetView.backgroundColor; //[self.mainTblView reloadData]; [self.menuView setBackgroundColor:appDel.barColor]; [_moodDetView setHidden:YES];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //For menu contents if (tableView.tag==2) { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; cell.textLabel.textColor = [UIColor whiteColor]; cell.textLabel.font = [UIFont fontWithName:@"Futura" size:14.0]; cell.textLabel.textAlignment = NSTextAlignmentCenter; cell.backgroundColor = [UIColor clearColor]; } switch (indexPath.row) { case 0: { cell.textLabel.text=@"Select Mood"; } break; case 1: { cell.textLabel.text=@"Search by Author"; } break; case 2: { cell.textLabel.text=@"Search by Category"; } break; case 3: { cell.textLabel.text=@"Favorites"; } break; case 4: { cell.textLabel.text=@"Feeds"; } break; default: break; } return cell; } //for main table else{ // Configure the cell... static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; FeedCustomCell* CELL=( FeedCustomCell *)cell; CELL.cellImageView.layer.cornerRadius=CELL.cellImageView.frame.size.width/2; CELL.cellImageView.clipsToBounds=YES; CELL.gesRec=[[CustomTapGestureRecognizer alloc]initWithTarget:self action:@selector(authorBtnTouched:)]; [CELL.lblAuthName setTextAlignment:NSTextAlignmentJustified]; [CELL.lblAuthName setTextColor:[AppDelegate invertColor:appDel.barColor]]; NSString * str=[NSString stringWithFormat:@"%@",[[dataArray objectAtIndex:indexPath.row] objectForKey:@"authorId"]]; UIImage * img=[UIImage imageNamed:str]; CELL.cellImageView.image=img?img:[UIImage imageNamed:@"n3"]; [CELL.lblAuthName addGestureRecognizer:CELL.gesRec]; CELL.gesRec.authorImage=CELL.cellImageView.image; NSString * authName=[[dataArray objectAtIndex:indexPath.row] objectForKey:@"authorName"]; [CELL.lblAuthName setText:authName]; [CELL.gesRec setAuthorId:(int)str.integerValue]; [CELL.gesRec setAuthorName:authName]; [CELL.txtViewQuote setTextColor:appDel.barColor]; CELL.txtViewQuote.text=[[dataArray objectAtIndex:indexPath.row] objectForKey:@"quoteTxt"]; CGSize sizeThatShouldFitTheContent = [CELL.txtViewQuote sizeThatFits:CELL.txtViewQuote.frame.size]; CELL.heightConstraintOfTxtView.constant = sizeThatShouldFitTheContent.height; [CELL.contentView sizeToFit]; return CELL; } }
问候:Syed Meesum Ali
初级软件开发人员
I'm developing an application on iOS targeting iOS 7.0 and later. Now, my question is that how to reload the rows of a UITableView which are visible on screen. I'm using dynamic cells.
Actually while selecting an option I'm changing some colors like title color of each cell but those cells which are already loaded on screen are not changed and if I'm loading whole table then its taking a long time.
Waiting for your kind reply.
Code
//on clicking this button color is updating
- (IBAction)btnDone:(id)sender { appDel.selectedMood=_moodDetView.str; appDel.barColor=_moodDetView.backgroundColor; self.navigationController.navigationBar.barTintColor = _moodDetView.backgroundColor; //[self.mainTblView reloadData]; [self.menuView setBackgroundColor:appDel.barColor]; [_moodDetView setHidden:YES];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //For menu contents if (tableView.tag==2) { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; cell.textLabel.textColor = [UIColor whiteColor]; cell.textLabel.font = [UIFont fontWithName:@"Futura" size:14.0]; cell.textLabel.textAlignment = NSTextAlignmentCenter; cell.backgroundColor = [UIColor clearColor]; } switch (indexPath.row) { case 0: { cell.textLabel.text=@"Select Mood"; } break; case 1: { cell.textLabel.text=@"Search by Author"; } break; case 2: { cell.textLabel.text=@"Search by Category"; } break; case 3: { cell.textLabel.text=@"Favorites"; } break; case 4: { cell.textLabel.text=@"Feeds"; } break; default: break; } return cell; } //for main table else{ // Configure the cell... static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; FeedCustomCell* CELL=( FeedCustomCell *)cell; CELL.cellImageView.layer.cornerRadius=CELL.cellImageView.frame.size.width/2; CELL.cellImageView.clipsToBounds=YES; CELL.gesRec=[[CustomTapGestureRecognizer alloc]initWithTarget:self action:@selector(authorBtnTouched:)]; [CELL.lblAuthName setTextAlignment:NSTextAlignmentJustified]; [CELL.lblAuthName setTextColor:[AppDelegate invertColor:appDel.barColor]]; NSString * str=[NSString stringWithFormat:@"%@",[[dataArray objectAtIndex:indexPath.row] objectForKey:@"authorId"]]; UIImage * img=[UIImage imageNamed:str]; CELL.cellImageView.image=img?img:[UIImage imageNamed:@"n3"]; [CELL.lblAuthName addGestureRecognizer:CELL.gesRec]; CELL.gesRec.authorImage=CELL.cellImageView.image; NSString * authName=[[dataArray objectAtIndex:indexPath.row] objectForKey:@"authorName"]; [CELL.lblAuthName setText:authName]; [CELL.gesRec setAuthorId:(int)str.integerValue]; [CELL.gesRec setAuthorName:authName]; [CELL.txtViewQuote setTextColor:appDel.barColor]; CELL.txtViewQuote.text=[[dataArray objectAtIndex:indexPath.row] objectForKey:@"quoteTxt"]; CGSize sizeThatShouldFitTheContent = [CELL.txtViewQuote sizeThatFits:CELL.txtViewQuote.frame.size]; CELL.heightConstraintOfTxtView.constant = sizeThatShouldFitTheContent.height; [CELL.contentView sizeToFit]; return CELL; } }
regards: Syed Meesum Ali
Junior Software Developer
原文:https://stackoverflow.com/questions/27860288
最满意答案
如果入口事件很快发生,则通常使用软件过滤器来忽略虚假区域退出事件。
为了使其独立于任何一个ViewController,重要的是让AppDelegate触发逻辑。 这里有两个选择:
将区域监视回调和过滤逻辑直接放在AppDelegate中。 这适用于小而简单的应用程序。
将回调和过滤逻辑放在自定义类中,并从AppDelegate的didFinishLaunching方法初始化它。 对于更大,更复杂的应用程序来说,这是保持AppDelegate简单和干净的最佳方法。
无论哪种方式, 从didFinishLaunching方法触发监控的开始至关重要。 如果应用程序通过区域转换自动启动,这可确保正确的后台CoreLocation设置。
It is common to use a software filter to ignore spurious region exit events if an entry event happens soon afterward.
To make this independent of any one ViewController, it is important to have the logic triggered by the AppDelegate. Two choices here:
Put region monitoring callbacks and filter logic directly in the AppDelegate. This is appropriate for small and simple apps.
Put callbacks and filter logic in a custom class, and initialize it from the AppDelegate's didFinishLaunching method. This is the best approach for larger and more complex apps to keep the AppDelegate simple and clean.
Either way, it is critical to trigger starting of monitoring from the didFinishLaunching method. This ensures proper background CoreLocation setup should your app be auto launched by region transitions.
相关问答
更多-
iOS设备可以监控自己的信标(它正在广告)吗?(Can an iOS device monitor its own beacon (one that it is advertising)?)[2022-01-14]
很不幸的是,不行。 CoreLocation和CoreBluetooth都不会选择由同一设备传输的广告。 这不应该是真正令人惊讶的,因为该设备具有单个蓝牙无线电,因此它不能同时发送和接收。 Unfortunately, no. Neither CoreLocation nor CoreBluetooth will pick up an advertisement transmitted by the same device. This should not really be surprising as t ... -
iOS区域监控(iOS Region Monitoring)[2023-07-12]
您可能只需要设置: startMonitoringForRegion: stopMonitoringForRegion: 然后,只需实现您输入的委托方法即可。 You probably only need to set: startMonitoringForRegion: stopMonitoringForRegion: Then once just implement the delegate methods you entered. -
iBeacon监控在后台(iBeacon monitoring in background)[2023-12-14]
在iOS 7.1上 , 背景检测时间仍然需要15分钟 ,特别是在iPhone 4S等旧型号上。 我做过测试来证明这一点,你可以在这里阅读: http : //developer.radiusnetworks.com/2014/03/12/ios7-1-background-detection-times.html 可以让您的应用程序在后台保持活动状态,以便这些检测器更快,但除非您有导航或音频应用程序,允许应用程序商店批准特殊背景模式, 您一次限制为3分钟的后台活动 。 有关详细信息,请参阅此处: http ... -
背景iOS中的信标监控(Beacon monitoring in background iOS)[2023-03-19]
如果入口事件很快发生,则通常使用软件过滤器来忽略虚假区域退出事件。 为了使其独立于任何一个ViewController,重要的是让AppDelegate触发逻辑。 这里有两个选择: 将区域监视回调和过滤逻辑直接放在AppDelegate中。 这适用于小而简单的应用程序。 将回调和过滤逻辑放在自定义类中,并从AppDelegate的didFinishLaunching方法初始化它。 对于更大,更复杂的应用程序来说,这是保持AppDelegate简单和干净的最佳方法。 无论哪种方式, 从didFinishLau ... -
是的,可以使用Android Beacon Library在后台检测Eddystone信标。 您可以使用与AltBeacon或iBeacon相同的方式执行此操作。 详细信息在样本的背景部分的Starting App中描述。 编辑:作为fof库版本2.7,添加了对Eddystone框架的硬件加速发现的支持,这意味着在Android 5+设备上,您可以在大约5秒内获得背景检测。 基本思想是你需要为你的应用程序创建一个中央android Application类,并在RegionBootstrap的onCreat ...
-
ios中的区域监控7(Region monitoring in ios 7)[2023-08-10]
现在这是从iOS7开始的预期行为。 在iOS6及更早版本中,即使您从应用程序切换器手动终止应用程序,当用户进入/退出某个区域时,您仍会收到通知。 iOS7的此行为已更改 。 如果用户已从应用切换器中杀死了该应用,即通过向上滑动您的应用,则他们将不再接收任何基于位置的通知,包括区域监控通知。 Apple官方开发人员论坛中的Apple员工证实了这一点 - 请点击此处链接 。 Apple Dev提供的唯一解决方案是“请提交错误报告,如果此更改对您有用,或者您希望看到不同的内容。” 我个人认为这是一个可怕的决定,因 ... -
您无法使用监控API读取单个信标标识符。 您所能做的就是访问用于开始监控的CLBeaconRegion标识符。 在你的情况下,这可能只是ProximityUUID的主要和次要零。 另一种方法是将测距与背景监测相结合 。 每当你收到didEnterRegion事件时,即使你的应用程序在后台,你也可以获得大约10秒的测距回调。 您可以使用此回调来读取所有标识符。 虽然前景中的测距使用的电池比监测电池多得多,但背景测距实际上非常适合电池使用。 考虑到每次进入或退出某个区域时,您只会持续10秒。 (即使测距仍然打开 ...
-
使用iOS CoreLocation, 无论信标广告的信号强度如何,都会在首次检测到与该区域匹配的信标时进行didEnterRegion监视回调。 当蓝牙芯片首次看到广告时,应该触发回调,这对于iOS和Android设备来说应该处于相似的范围。 虽然最大蓝牙检测范围肯定会因设备而异,并且可能会因添加一个外壳,将手机放入口袋或受阻碍而影响,但在典型使用中它并没有太大变化。 更可能解释为什么你看到检测延迟的是时间,而不是信号强度。 在后台,iOS将遵循蓝牙芯片硬件检测插槽,以快速匹配您的信标区域。 这是一种有限 ...
-
来自Beacon iOS的背景通知使用ESTBeaconManager(Background Notification from Beacon iOS using ESTBeaconManager)[2022-05-29]
我怀疑您的应用尚未获得位置权限。 要进行验证,请转到“设置” - >并检查您的应用是否具有“始终”位置权限。 如果是,它应该如下面的截图。 如果您没有授予位置访问权限,请检查请求它的代码。 除了你的plist中的条目,你需要这样的东西: if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { [locationManager requestAlwaysAuthorization]; } I sus ... -
问题可能很简单。 您的代码示例正在为所有区域重用相同的区域标识符"RegionID" 。 请使用不同的。 Problem might be very simple. Your code sample is reusing the same region identifier "RegionID" for all regions. Please use different ones.