Tag: 客观

如何避免UITableViewCell重复添加自定义标签时,TableView滚动?

我创build一个自定义单元格: #import <UIKit/UIKit.h> #import "RecruitmentResumeEntity.h" @interface RecruimentListItemCell : UITableViewCell @property (nonatomic, strong) RecruitmentResumeEntity *entity; @end 在.m文件中设置实体方法我添加三个标签: -(void)setEntity:(RecruitmentResumeEntity *)entity { _entity = entity; float labelHeight = 17; CGRect frame = CGRectMake(64, 45, 0, labelHeight); UILabel *cityLabel = [self createTagLabelWithFrame:frame text:_entity.city backgroundColor:@"#e5986f"]; [self.contentView addSubview:cityLabel]; UILabel *workExperienceLabel = [self createTagLabelWithFrame:CGRectMake(cityLabel.x+cityLabel.width +10, cityLabel.y, 0, labelHeight) text:[NSString stringWithFormat:@"%@年",_entity.workExperience] backgroundColor:@"#81A0D7"]; [self.contentView […]

主页button被按下时,CABasicAnimation消失

我正在实施一个游戏,其中我有一些CABasicAnimations。 例如,像这样: CABasicAnimation * borddroit = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; borddroit.fromValue = [NSNumber numberWithFloat:0.0f]; borddroit.toValue = [NSNumber numberWithFloat:749.0f]; borddroit.duration = t; borddroit.repeatCount = 1; [ImageSuivante2.layer addAnimation:borddroit forKey:@"borddroit"]; 我用这个函数暂停: -(void)pauseLayer:(CALayer*)layer { CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; layer.speed = 0.0; layer.timeOffset = pausedTime; } 当我的应用程序进入后台,因为用户按下home键,animation正确设置暂停,但是当我重新打开我的应用程序,animation已经消失。 我怎么能修好它? 谢谢

自定义UITableViewCell prepareForReuse不按预期方式工作

我的prepareForReuse工作不正常。 我有一个UITableView应该有一个login UIButton在表的第一部分的第一行只。 但是,在prepareForReuse ,当我删除loginbutton时,它保持并进入下一批的行。 (video来说明 – > http://pixori.al/8g3v ) 这是我的自定义UITableViewCell : #import "MAGradeCell.h" @implementation MAGradeCell – (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier cellForRowAtIndexPath:(NSIndexPath *)indexPath { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code } return self; } -(void)layoutSubviews{ [super layoutSubviews]; } – (void)prepareForReuse { self.loginButton = nil; [self removeFromSuperview]; [self.loginButton removeFromSuperview]; self.textLabel.text = nil; […]

检测旋转UIViews之间的冲突

我有两个UIViews,其中之一是旋转每0.01秒使用以下代码: self.rectView.transform = CGAffineTransformRotate(self.rectView.transform, .05); 现在,我想知道另一个名为view的UIView是否与rectView相交。 我用这个代码: if(CGRectIntersectsRect(self.rectView.frame, view.frame)) { //Intersection } 但是,你可能知道有一个问题。 这是一个截图: 在这种情况下,检测到碰撞,尽pipe显然他们没有碰触。 我环顾四周,但我似乎无法find真正的代码来检测这种冲突。 如何才能做到这一点? 在这种情况下检测碰撞的工作代码将不胜感激! 或者也许会有比UIView更好的类使用?

用`dispatch_barrier`死锁

通过学习dispatch_barrier ,我写了一个例子如下: static dispatch_queue_t queue; static dispatch_queue_t readWriteLockQueue; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ queue = dispatch_queue_create("com.test.testasync", DISPATCH_QUEUE_CONCURRENT); readWriteLockQueue = dispatch_queue_create("com.test.readWriteLockQueueOfMeta", DISPATCH_QUEUE_CONCURRENT); }); for (NSInteger i=0; i<100; i++) { dispatch_async(queue, ^{ dispatch_sync(readWriteLockQueue, ^{ NSLog(@"read"); }); dispatch_barrier_sync(readWriteLockQueue, ^{ NSLog(@"write"); }); }); } dispatch_barrier_async(queue, ^{ NSLog(@"finished!"); }); 但是输出结果是: 2016-05-20 16:23:14.066 Test[23867:781553] read 2016-05-20 16:23:14.066 Test[23867:781555] read 2016-05-20 16:23:14.066 […]

从图像的URL数组中添加图像到UITableViewCell

我有一个图像的URL数组,我想显示在UITableView单独的单元格上的每个URL的图像。 在我之前使用的代码中: UIImageView *view_Image = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, 400, 180)]; view_Image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:arrURL[i]]]]; 这是在一个for循环内,使得每个UIImageView的x,y和i的值都会改变。 但是,这种方法不起作用,当我在cellForRowAtIndexPath使用此。 图像没有得到显示,我的cellForRowAtIndexPath实现是: -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *simpleIdentifier = @"simpleIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleIdentifier]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleIdentifier]; } cell.textLabel.text = _arrNames[indexPath.row]; UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 300, […]

拉下UIScrollView并保持y位置

我想在UIScrollView被拉到某一点时触发一个动作。 这就是我现在所拥有的: – (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView.contentOffset.y == -100.0) { NSLog(@"Trigger"); [scrollView setContentOffset:CGPointMake(0.0, -200.0) animated:YES]; } } 这种工作,直到我结束我的触摸事件,然后UIScrollView返回到它的原始位置。 任何想法如何解决这个问题?

不断检测互联网连接

我想让我的应用程序自动检测互联网连接丢失。 所以即时通讯使用下面的代码。 – (void)applicationDidBecomeActive:(UIApplication *)application { Reachability *networkReachability = [Reachability reachabilityForInternetConnection]; NetworkStatus networkStatus = [networkReachability currentReachabilityStatus]; if (networkStatus == NotReachable) { [Settings hideSpinner]; //Show no internet connectivity dialog. } else { } } 但问题是,它不是连续检查互联网连接。 它只在应用程序激活时才检查。 如何在整个应用生命周期中连续检查互联网连接,并在互联网自动closures时发出警告?

本地通知何时didEnterRegion?

我有以下代码,当应用程序终止工作完美。 -(void)beaconManager:(id)manager didEnterRegion:(CLBeaconRegion *)region{ UILocalNotification *notification = [UILocalNotification new]; notification.alertBody = @"TEST NOTIFICATION"; notification.soundName = UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; } 但是,当我做到以下几点: -(void) createTestNotification { UILocalNotification *notification = [UILocalNotification new]; notification.alertBody = @"TEST"; notification.soundName = UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; } -(void)beaconManager:(id)manager didEnterRegion:(CLBeaconRegion *)region{ [self createTestNotification]; } 这是行不通的 ? 我只把我的代码移到外面没有别的? 我知道,当didEnterRegion被调用时,应用程序将只有5秒,但调用此方法不会花费这个时间? 更新1: 我刚刚发现区域 didEnterRegion返回的是我开始监测,而不是属于应用程序刚才看到它的信标的那个。我打算使用这个区域来获取我的自定义味精取决于该地区的主要和次要 。 但在我的情况下是不可能的,所以我开始测距,当didEnterRegion被调用,然后在didRangeBeacons返回信标数组我得到了属于这个信标的文本信息从本地数据库 “取决于主要和次要的” […]

滚动时,UITableViewCell detailTextLabel消失

我使用了一个string数组,我detailTextLabel设置了detailTextLabel 。 最初所有的字幕设置正确,但如果我滚动detailTextLabel消失。 – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"personCell" forIndexPath:indexPath]; Person *person = [_persons objectAtIndex:indexPath.row]; cell.textLabel.text = person.name; cell.detailTextLabel.text = person.phone; // also tried setNeedsLayout but does not help [cell setNeedsLayout]; return cell; } 我正在使用iPhone 6和iOS 8.我也使用故事板,并将UITableViewCell样式设置为Subtitle 。