我最近刚试着用一个样本应用试图让我的脑袋完全缠绕NSRunLoop.我编写的示例创建了一个简单的辅助线程via NSOperation.辅助线程执行一些任务,例如处理NSTimer和一些基本的流媒体NSStream.这两个输入源都需要正确配置NSRunLoop才能执行.
我的问题是这个.最初我在辅助线程中有一些看起来像这样的代码:
NSRunLoop* myRunLoop = [NSRunLoop currentRunLoop];
self.connectTimer = [NSTimer scheduledTimerWithTimeInterval:connectTimeout
target:self
selector:@selector(connectionConnectedCheck:)
userInfo:nil
repeats:NO];
[myRunLoop addTimer:self.connectTimer forMode:NSDefaultRunLoopMode]; // added source here
[myRunLoop run];
[NSStream getStreamsToHostNamed:relayHost port:relayPort inputStream:&inputStream outputStream:&outputStream];
if ((inputStream != nil) && (outputStream != nil))
{
sendState = kSKPSMTPConnecting;
isSecure = NO;
[inputStream retain];
[outputStream retain];
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop: myRunLoop //[NSRunLoop currentRunLoop]
forMode:NSRunLoopCommonModes];
[outputStream scheduleInRunLoop: myRunLoop //[NSRunLoop currentRunLoop]
forMode:NSRunLoopCommonModes];
[inputStream open];
[outputStream open];
self.inputString = …Run Code Online (Sandbox Code Playgroud) 我有一个简单的应用程序,我有一个表视图和依赖于数组的回调我使用reloadData方法重新加载表数据.最初加载前5-10次这个表视图没有任何问题.在使用应用程序之后,有时我注意到表视图是空白的,因为cellForRowAtIndexPath框架没有调用它.我验证了datasource&delegate设置正确并numberOfRowsInSection返回有效的正数.一旦我看到空白表视图,我就可以反复看到这个空白视图,直到我退出应用程序.我在控制台中没有收到任何错误或警告.我试图调整阵列但无济于事.
这是代码:
- (void)notifyArrayLoaded:(NSArray *)arr {
NSUInteger capacity = [arr count];
_tbDataArray = [[NSMutableArray alloc] initWithCapacity:capacity];
// _tbDataArray is filled with the data from arr
// Reload the table data
[_tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
任何线索都将受到高度赞赏.
提前致谢.萨米特
嗨DeanWombourne,我没有viewDidUnLoad方法,但我有viewWillDisAppear方法,我在这里发布它.
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:NO];
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];
view.transform = CGAffineTransformIdentity; …Run Code Online (Sandbox Code Playgroud) 我有一个NSMutableArray实体类对象作为其对象.现在我想从中删除不同的对象.考虑以下示例
Entity *entity = [[Entity alloc] init];
entity.iUserId = 1;
entity.iUserName = @"Giri"
[arr addObject:entity];
Entity *entity = [[Entity alloc] init];
entity.iUserId = 2;
entity.iUserName = @"Sunil"
[arr addObject:entity];
Entity *entity = [[Entity alloc] init];
entity.iUserId = 3;
entity.iUserName = @"Giri"
[arr addObject:entity];
Run Code Online (Sandbox Code Playgroud)
现在我只想Array删除重复的iUserName 中的两个对象.我知道通过迭代的方式,但我想要它,而不是像predicate其他方式迭代它.如果有人知道那么请帮助我.我曾尝试过使用[arr valueForKeyPath:@"distinctUnionOfObjects.iUsername"];但它不会让我退回已经退出的物体.
这个问题与之前提出的问题完全不同.以前问的问题是让不同的对象是正确的,但他们使用循环而我不想这样.我希望它NSPredicate或任何其他简单的选项,以避免循环.
我有一个UITextfield&我将应用垂直对齐(顶部,底部,中心).我通过设置垂直对齐来正确完成.但是当我使用(-M_PI/2)并应用底部或中心对齐来转换文本字段时,它工作正常但文本字段中的文本对用户不可见.如果有人知道有关此问题的解决方案,请帮助我.提前致谢.
我知道我们可以只使用a NSMutableArray作为对象,但如果这不是一个选项,我们需要添加新的元素NSArray.我们该怎么做呢?
我的直接答案是创建一个NSMutableArray原始的NSArray,添加新的元素,然后再NSMutableArray回到原始NSArray.
我在接受采访时被问到这个问题,我很好奇一个正确的解决方案是什么,除了一开始就使用a NSMutableArray.
我有NSArray一些NSDictionaries自己也包括一个NSDictionary.
NSDictionary *dict1 = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:@"cover" forKey:@"type"] forKey:@"image"];
NSDictionary *dict2 = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:@"cover" forKey:@"type"] forKey:@"image"];
NSDictionary *dict3 = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:@"back" forKey:@"type"] forKey:@"image"];
NSDictionary *dict4 = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:@"cover" forKey:@"type"] forKey:@"image"];
NSArray *myArray = [NSArray arrayWithObjects:dict1, dict2, dict3, dict4, nil];
Run Code Online (Sandbox Code Playgroud)
有没有办法过滤myArray所有图像字典,其中类型是使用NSPredicate fe"覆盖"?
尝试谓词喜欢
predicateWithFormat:@"(SELF.image.type == %@)", @"cover"]
Run Code Online (Sandbox Code Playgroud)
要么
predicateWithFormat:@"(image.type == %@)", @"cover"]
Run Code Online (Sandbox Code Playgroud)
但没有成功.
提前致谢!如果不清楚,请发表评论
所以
NSPredicate *p = [NSPredicate predicateWithFormat:@"image.type == %@", @"cover"];
Run Code Online (Sandbox Code Playgroud)
工作中.但在我的情况下,我想整理尺寸==原始.我做的是
NSPredicate *p = [NSPredicate predicateWithFormat:@"image.size …Run Code Online (Sandbox Code Playgroud) 我有Seprate UIView我正在使用UIViewController它最初加载但我希望当它加载,我再次点击按钮然后它应该重新加载,因为它有图形创建方法,当视图加载时绘制图形
#import <UIKit/UIKit.h>
#import "ECGraph.h"
#import "ECGraphItem.h"
#import "CereniaAppDelegate.h"
@class GraphsViewController;
@interface Display : UIView {
NSArray *percentages;
CereniaAppDelegate*appDelegate;
}
@property(nonatomic,retain)NSArray*percentages;
-(void) setPercentageArray:(NSArray*) array;
@end
Run Code Online (Sandbox Code Playgroud)
实施文件
#import "Display.h"
#import "ECGraph.h"
#import "CereniaAppDelegate.h"
@implementation Display
@synthesize percentages;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef _context = UIGraphicsGetCurrentContext();
ECGraph *graph = [[ECGraph alloc] initWithFrame:CGRectMake(70,-70,800,200) withContext:
_context isPortrait:NO];
appDelegate=[[UIApplication sharedApplication]delegate];
ECGraphItem *item1 = [[ECGraphItem alloc] init];
ECGraphItem *item2 …Run Code Online (Sandbox Code Playgroud) 我有一个UIButton和一个UIView动画,按下时向下滑动UIButton.问题是UIView模糊了UIButton.我希望UIButton始终保持领先地位.
我试过这个viewDidLoad:
[self.view bringSubviewToFront:categoryBtn];
Run Code Online (Sandbox Code Playgroud)
虽然不起作用.
谢谢你的帮助
是否可以安全地添加NSOperationQueue到一个NSOperation,然后将此操作添加到另一个NSOperationQueue?
这里有一些代码可视化我想要做的事情.
NSOperationQueue *mainQueue = [NSOperationQueue alloc] init];
// Here I declare some NSBlockOperation's, i.e. parseOperation1-2-3
// and also another operation called zipOperation, which includes
// an NSOperationQueue itself. This queue takes the processed (parsed) files
// and write them to a single zip file. Each operation's job is to write the data
// stream and add it to the zip file. After all operations are done,
// it closes the zip.
[zipOperation addDependency:parseOperation1]; …Run Code Online (Sandbox Code Playgroud) 我想在iOS6中获取视频的所有帧NSArray.我用这个代码:
-(void) getAllImagesFromVideo
{
imagesArray = [[NSMutableArray alloc] init];
times = [[NSMutableArray alloc] init];
for (Float64 i = 0; i < 15; i += 0.033) // For 25 fps in 15 sec of Video
{
CMTime time = CMTimeMakeWithSeconds(i, 60);
[times addObject:[NSValue valueWithCMTime:time]];
}
[imageGenerator generateCGImagesAsynchronouslyForTimes:times completionHandler:^(CMTime requestedTime, CGImageRef image, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error) {
if (result == AVAssetImageGeneratorSucceeded)
{
UIImage *generatedImage = [[UIImage alloc] initWithCGImage:image];
[imagesArray addObject:generatedImage];
}
}];
}
Run Code Online (Sandbox Code Playgroud)
在iPad模拟器上,延迟是90~100秒,在iPad设备上,收到内存警告,最后崩溃.
任何想法,解决方案?使用另一个更低级的框架/库?C++?对我来说非常重要!帮我!:)
谢谢!!!
objective-c ×9
ios ×6
iphone ×5
cocoa-touch ×2
avfoundation ×1
cocoa ×1
frame-rate ×1
nsarray ×1
nsdictionary ×1
nsoperation ×1
nspredicate ×1
uibutton ×1
uitableview ×1
uitextfield ×1
uiview ×1
xcode ×1