首页 \ 问答 \ 重新加载tableview的活动单元格(Reloading Active cells of tableview)

重新加载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
更新时间:2023-03-05 22:03

最满意答案

如果入口事件很快发生,则通常使用软件过滤器来忽略虚假区域退出事件。

为了使其独立于任何一个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.

相关问答

更多
  • 很不幸的是,不行。 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 ...
  • 您可能只需要设置: startMonitoringForRegion: stopMonitoringForRegion: 然后,只需实现您输入的委托方法即可。 You probably only need to set: startMonitoringForRegion: stopMonitoringForRegion: Then once just implement the delegate methods you entered.
  • 在iOS 7.1上 , 背景检测时间仍然需要15分钟 ,特别是在iPhone 4S等旧型号上。 我做过测试来证明这一点,你可以在这里阅读: http : //developer.radiusnetworks.com/2014/03/12/ios7-1-background-detection-times.html 可以让您的应用程序在后台保持活动状态,以便这些检测器更快,但除非您有导航或音频应用程序,允许应用程序商店批准特殊背景模式, 您一次限制为3分钟的后台活动 。 有关详细信息,请参阅此处: http ...
  • 如果入口事件很快发生,则通常使用软件过滤器来忽略虚假区域退出事件。 为了使其独立于任何一个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 ...
  • 现在这是从iOS7开始的预期行为。 在iOS6及更早版本中,即使您从应用程序切换器手动终止应用程序,当用户进入/退出某个区域时,您仍会收到通知。 iOS7的此行为已更改 。 如果用户已从应用切换器中杀死了该应用,即通过向上滑动您的应用,则他们将不再接收任何基于位置的通知,包括区域监控通知。 Apple官方开发人员论坛中的Apple员工证实了这一点 - 请点击此处链接 。 Apple Dev提供的唯一解决方案是“请提交错误报告,如果此更改对您有用,或者您希望看到不同的内容。” 我个人认为这是一个可怕的决定,因 ...
  • 您无法使用监控API读取单个信标标识符。 您所能做的就是访问用于开始监控的CLBeaconRegion标识符。 在你的情况下,这可能只是ProximityUUID的主要和次要零。 另一种方法是将测距与背景监测相结合 。 每当你收到didEnterRegion事件时,即使你的应用程序在后台,你也可以获得大约10秒的测距回调。 您可以使用此回调来读取所有标识符。 虽然前景中的测距使用的电池比监测电池多得多,但背景测距实际上非常适合电池使用。 考虑到每次进入或退出某个区域时,您只会持续10秒。 (即使测距仍然打开 ...
  • 使用iOS CoreLocation, 无论信标广告的信号强度如何,都会在首次检测到与该区域匹配的信标时进行didEnterRegion监视回调。 当蓝牙芯片首次看到广告时,应该触发回调,这对于iOS和Android设备来说应该处于相似的范围。 虽然最大蓝牙检测范围肯定会因设备而异,并且可能会因添加一个外壳,将手机放入口袋或受阻碍而影响,但在典型使用中它并没有太大变化。 更可能解释为什么你看到检测延迟的是时间,而不是信号强度。 在后台,iOS将遵循蓝牙芯片硬件检测插槽,以快速匹配您的信标区域。 这是一种有限 ...
  • 我怀疑您的应用尚未获得位置权限。 要进行验证,请转到“设置” - >并检查您的应用是否具有“始终”位置权限。 如果是,它应该如下面的截图。 如果您没有授予位置访问权限,请检查请求它的代码。 除了你的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.

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)