Tag: 客观

drawRect和CGGraphicsContext如何工作?

我在Core Graphic的一些工作,我正在寻找一些关于几个主题的额外澄清。 drawRect:我已经理解了这一点,知道它是UIView所有绘图方面的内容,但是我不清楚这个场景背后发生了什么。 当我创build一个UIView并填写drawRect,然后将另一个对象的UIView设置为该自定义视图时会发生什么? drawRect何时被调用? CGGraphicsContext:我知道这是什么目的,并理解这个概念,但是我看不出它是如何工作的。 例如: CGContextSaveGState(context); CGContextAddRect(context, rect); CGContextClip(context); CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0); CGContextRestoreGState(context); 上面的代码在我的应用程序和工作是正确的。 让我困惑的是它是如何工作的。 保存/恢复上下文的想法是有道理的,但是看起来像我从字面上保存上下文,使用完全相同的上下文来进行更改,然后再次恢复相同的上下文。 这看起来像是我正在保存一个上下文,然后写在上下文的顶部,只是为了恢复它。 如何将它保存到恢复它的位置,这与刚刚用于进行更改的环境是不同的实例? 在任何情况下,都使用相同的variables上下文的引用。 最后,我将不胜感激任何资源的实践项目或使用核心graphics的例子。 我希望提高我在这个问题上的技巧,因为我目前显然没有太多。

通过GCD延迟睡眠()

每次我打电话时,我都有需要延迟5秒的方法。 首先我要sleep(5); – 它运作良好,但我相信 – 这不是客观的方式,所以我试图用GCD的帮助来写它。 这个程序的第一个呼叫延迟约5秒,但这个队列中的其他呼叫将一个接一个地延迟。 如何解决这个问题呢? – (void) buyItemAtUUID:(NSString*)UUID { dispatch_barrier_async(dataManagerQueue, ^{ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; double delayInSeconds = 5.0; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dataManagerQueue, ^(void){ NSInteger path = [self indexFromObjectUUID:UUID]; if (path != NSNotFound) { NSMutableDictionary *item = [[_items objectAtIndex:path] mutableCopy]; NSNumber *value = [NSNumber numberWithFloat:[[item objectForKey:@"Quantity"] floatValue] – […]

有可能在一个xib中创build多个单元格吗?

我发现它可以用不同的xib创build不同的单元格,但是我想知道是否可以在一个xib中创build不同的单元格? 如果可能,我该怎么做? 这里是代码,我知道这是错误的代码,所以你们可以帮我解决它吗? – (void)viewDidLoad { [super viewDidLoad]; [imageTableView registerNib:[UINib nibWithNibName:@"ImageTableViewCell" bundle:nil] forCellReuseIdentifier:@"oneImageTableViewCell"]; [imageTableView registerNib:[UINib nibWithNibName:@"ImageTableViewCell" bundle:nil] forCellReuseIdentifier:@"twoImageTableViewCell"]; } – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *identifier1 = @"oneImageTableViewCell"; NSString *identifier2 = @"twoImageTableViewCell"; if (indexPath.row % 2 == 0) { ImageTableViewCell *cell = [imageTableView dequeueReusableCellWithIdentifier:identifier1 forIndexPath:indexPath]; return cell; } else { ImageTableViewCell *cell = [imageTableView […]

如何使用commitEditingStyle从plist删除数组?

我有一个UITableView由plist的数组键通过此代码填充: -(void)viewWillAppear:(BOOL)animated { // get paths from root direcory NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); // get documents path NSString *documentsPath = [paths objectAtIndex:0]; // get the path to our Data/plist file NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:(NSString *)plistPath]; viewerKeys = [dictionary allKeys]; [self.tableView reloadData]; } – (UITableViewCell *)tableView:(UITableView *)tableView […]

滚动时,UITableView单元格变空白

我已经在UITableViewController中设置了单个部分,单个单元格自定义单元格来显示比屏幕更长的视图。 但是在testing时,我注意到在离开视图区域之前向下滚动时单元格会消失(空白)。 这不是什么幻想,但我不明白为什么滚动下来会消失,尤其是当它远离可视区域时。 – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { VendorDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VendorDetailCell"]; cell.vendorImage.image = [UIImage imageWithData: self.imageData.data]; cell.vendorTitle.text = self.imageData.vendorTitle; cell.vendorDescription.text = self.imageData.vendorDescription; return cell; }

search视图总是显示在桌面上

我拿了一个UITableViewController,并试图在其中添加UISearchDisplayController。 我从互联网阅读了很多代码,但不知道我的错在哪里。 我的问题是为什么UISearchDisplayController不要总是坚持在UITableView之上。 这是我的代码 SearchView_controller.h @interface SearchView_controller : UITableViewController<UISearchBarDelegate,UISearchDisplayDelegate> @end SearchView_controller.m @interface SearchView_controller () { UISearchDisplayController *searchController; } @end @implementation SearchView_controller – (void)viewDidLoad { [super viewDidLoad]; self.title=@"Test"; UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, self.tableView.frame.origin.y, self.tableView.frame.size.width, 44)]; [searchBar sizeToFit]; [searchBar setDelegate:self]; searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]; [searchController setSearchResultsDataSource:self]; [searchController setSearchResultsDelegate:self]; [searchController setDelegate:self]; [self.tableView setTableHeaderView:searchController.searchBar]; } […]

在静态表格视图中dynamic调整文本视图和表格视图单元格的大小

我有一个静态表视图,我正在使用作为我的应用程序的数据inputsot。 其中一个单元格中有一个UITextView,它需要随着用户的input而dynamic增长和缩小,以及逻辑上随着单元格的增长/收缩。 我读了一堆这个post,但我想我正在被抛出,因为我正在使用一个STATIC表视图。 这里是我resize的尝试(它几乎总是失败): – (void)textViewDidChange:(UITextView *)textView { self.numberOfLines = (textView.contentSize.height / textView.font.lineHeight) – 1; float height = 44.0; height += (textView.font.lineHeight * (self.numberOfLines – 1)); CGRect textViewFrame = [textView frame]; textViewFrame.size.height = height – 10.0; //The 10 value is to retrieve the same height padding I inputed earlier when I initialized the UITextView [textView […]

iOS 7 – UISegmentedControl没有保持突出显示?

我有一个UISegmentedControl显示在我的UINavigationBar在运行iOS 7的iPhone应用程序。我注意到,当我selectUISegmentedControl中的一个值突出显示不保持活动。 也就是说,如果我select了第一个项目,它会触发我添加到其中的操作,但是会立即取消突出显示我select的值。 这是预期的行为? 一个错误? 我不记得曾经在使用这个控件的其他应用程序中看到这一点,它在iOS 6上工作得很好。

UITableView重复Firebase数据

我正在从Firebase获取重复的内容,而我似乎无法弄清楚我做错了什么。 在firebase我有6个职位。 tableview是填充6个单元格,但所有6个单元格具有相同的数据,其他5个职位不在那里。 – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { RankingsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RankingsCell"]; self.ref = [[FIRDatabase database] reference]; posts = [ref child:@"posts"]; [posts observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) { for (snapshot in snapshot.children) { NSString *username = snapshot.value[@"Name"]; NSString *date = snapshot.value[@"Date"]; NSString *combatPower = snapshot.value[@"Combat Power"]; NSString *pokemon = snapshot.value[@"Pokemon"]; NSString *pokemonURL = snapshot.value[@"Pokemon […]

SecCertificateCreateWithData总是返回null

我目前正在从以下职位工作 。 这里是代码: SecCertificateRef certs = NULL; SecPolicyRef policy = NULL; NSString *publicKeyString = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCeJ8N8fuGShAJnniDg4yuRrxrG61ZF2T24eXSEH87jCJmLbc+MV70AgP/LC8btzSU4FFP56lBmDcmW+Prupf5gO1RXhjPIlET73t5Ny1I3ze+xaShAA9qB0c9dNb26NxVd95wCHNmQhon9qBFmTVZb0CdgscxYcDuLOGskDnATrwIDAQAB"; NSData *publicKeyStringData = [[NSData alloc] initWithBase64EncodedString:publicKeyString options:0]; certs = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef) publicKeyStringData); 如果certsvariables为NULL,则基于post,数据格式不正确。 我检查了上面的公钥,它确实是base64,所以我不明白为什么certs将是NULL?