我创建了一个应该运行的应用程序,直到我停止它.它基本上做的是从连接的另一个设备获取一些数据NSURLConnection,并定期使用该数据发送到服务器,并定期从服务器读取数据,并使用图形将该数据可视化NSXMLParser.
我运行仪器来检查分配和泄漏.完全没有泄漏.内存监视器显示一致的5.2 MB.Objectalloc图是稳定的,objectallo的净字节是480000,#net是6400左右.
它在大约10~15小时后坠毁.所以我添加了断点malloc_error_break.现在,EXC_BAD_ACCESS大约12小时后,我在调试器控制台上出现" "错误.
任何的想法?
一个可疑的部分是SENDING数据.
- (void) sendDataToServerWithX:(float)x Y:(float)y{
NSAutoreleasePool *uiUpdatePool = [[NSAutoreleasePool alloc] init];
NSString *urlString = [[NSString alloc] initWithFormat:@"http://www.url.com/save_data.php?user=user1&x=%f&y=%f", x, y];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) { NSLog(@"sending success"); }
//else { }
NSLog( @"data sent.");
[urlString release];
[theConnection release];
[uiUpdatePool drain];
}
另一个可疑部分是阅读数据:
- (void) readCurrentDataFromServer: (NSTimer *) timer {
NSAutoreleasePool *uiUpdatePool = …Run Code Online (Sandbox Code Playgroud) 我正在创建一个UITableViewCell类似于样式的自定义,UITableViewCellStyleValue1但右侧有一个可编辑的文本字段而不是detailTextLabel.我对如何正确调整编辑字段的大小感到困惑.我想考虑textLabel到帐户的长度,以及它的大小contentView,并且当它的表视图处于编辑模式时,或者如果添加了附件视图(如公开箭头)时,能够做正确的事.
但contentView即使对于分组表,宽度似乎总是320(在iPhone上以纵向模式).在我的UITableViewCell子类中,我看不到访问它所属的表视图的方法,因此我可以获得表的样式并相应地调整边距.
我想我可以在tableView的委托-tableView:willDisplayCell:forRowAtIndexPath:方法中以自定义方式处理这个问题,但这完全违背了拥有可重用单元类的目的.
我必须在这里遗漏一些关键概念,但我不知所措.任何人?
谢谢!兰迪
我有一个基本问题,在使用时NSOutputStream,我们是否应该等待NSStreamEventHasSpaceAvailable发送数据包,以便我们可以[NSOutputStream write]在需要时调用它,
我相信NSStream应该照顾写功能......
如果这不正确,那么请提供您对以下逻辑的看法,
=====写上NSOutputStream=================有队列添加数据包,即发送//StreamQueue.h
@interface StreamQueue : NSObject <NSCoding>
{
NSMutableArray * data;
NSRecursiveLock * theLock;
}
#pragma mark ?Initialization & Deallocation?
- (id)init;
- (id)initWithQueue:(CommQueue *)queue;
- (id)initWithCoder:(NSCoder *)coder;
- (void)dealloc;
- (void)encodeWithCoder:(NSCoder *)coder;
#pragma mark
#pragma mark ?Accessor Methods?
- (int)size;
- (BOOL)isEmpty;
- (id)top;
- (NSArray *)data;
#pragma mark
#pragma mark ?Modifier Methods?
- (void)enqueue:(id)object;
- (id)dequeue;
- (void)removeAll;
@end
Run Code Online (Sandbox Code Playgroud)
及其实施
#import "StreamQueue.h"
@implementation StreamQueue …Run Code Online (Sandbox Code Playgroud) 我使用的是UIPanGestureRecognizer一个UIView是一个UICollectionViewCell.我正在使用该translationInView方法获得沿X轴的平移并UIView向左和向右滑动.它工作正常,但现在我无法在CollectionView中上下滚动,如果我的手指在单元格上.有没有办法让PanGestureRecognizer传递垂直滚动到UICollectionView?
我试图复制在Reeder.app for iOS中看到的滑动.
cocoa-touch objective-c uipangesturerecognizer uicollectionview uicollectionviewcell
我正在应用渐变UIImage,我想让它在底部变暗,然后在中间慢慢变为透明或浅灰色.它基本上没问题,但我有一个问题,我的图像颜色在这个渐变下的某些地方反转.这看起来很烦人.我该如何解决?
这是我方便的方法.
我尝试过采用不同的混合模式,但它没有帮助.另一个问题是,如何在底部使黑色更加密集?
此方法无需任何额外代码即可运行.开始颜色[UIColor blackColor]和结束颜色是[UIColor clearColor]:
- (UIImage *)imageWithGradient:(UIImage *)img startColor:(UIColor *)color1 endColor:(UIColor *)color2 {
UIGraphicsBeginImageContextWithOptions(img.size, NO, img.scale);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, img.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetBlendMode(context, kCGBlendModeDarken); // tried normal here, same results
CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
CGContextDrawImage(context, rect, img.CGImage);
// Create gradient
NSArray *colors = [NSArray arrayWithObjects:(id)color1.CGColor, (id)color2.CGColor, nil];
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColors(space, (__bridge CFArrayRef)colors, NULL);
// Apply gradient
CGContextClipToMask(context, rect, img.CGImage);
CGContextDrawLinearGradient(context, …Run Code Online (Sandbox Code Playgroud) 我在将照片库中的图像附加到电子邮件时遇到了一些麻烦.
基本上,我的应用程序的一个功能允许用户拍照.当他们拍摄镜头时,我将URL参考记录到Core Data中的图像.我知道你必须通过去看ALAssetRepresentation图像.我已经在我的应用程序中运行并在用户想要查看他们已经拍摄的图像时运行.
我现在正试图允许用户将为活动拍摄的所有照片附加到电子邮件中.在执行此操作时,我遍历存储URL引用的Core Data实体,调用UIImage从中返回a的方法,ALAssetsLibrary然后使用NSData/ UIImageJPEGRepresentation和MFMailComposeViewController/ addAttachmentData方法将其附加.
问题是:当电子邮件呈现给用户时,表示图像的小蓝色方块没有附加图像.
这是代码:
- (void)sendReportReport
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Log: Report"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"someone@someco.com", nil];
[mailer setToRecipients:toRecipients];
NSError *error;
NSFetchRequest *fetchPhotos = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Photo" inManagedObjectContext:__managedObjectContext];
[fetchPhotos setEntity:entity];
NSArray *fetchedPhotos = [__managedObjectContext executeFetchRequest:fetchPhotos error:&error];
int counter;
for (NSManagedObject *managedObject in fetchedPhotos ) {
Photo …Run Code Online (Sandbox Code Playgroud) 我正在为iPhone创建一个名称生成器应用程序,这正是我想要做的.
为了做到这一点,这是正在发生的事情:
UILabel.NSMutableArray(我不认为这在我的代码中正常工作).NSMutableArray随后被保存在NSUserDefaults.UITableView单元格.我的具体问题是,我正确处理这个保存/持久存储过程吗?以下是相关代码段:
- (IBAction)saveName:(id)sender {
// save current baby name to array
NSMutableArray *babyNameArray = [[NSMutableArray alloc] init];
[babyNameArray addObject:babyname.text];
// save list of babynames to nsuserdefaults
[[NSUserDefaults standardUserDefaults] setObject:babyNameArray forKey:@"My Key"];
// for testing log names listed in nsuserdefaults
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
}
Run Code Online (Sandbox Code Playgroud)
这是一个指向整个文件内容的pastebin的链接(带注释):http://pastebin.com/hQRM9Azh
我试图以UILabel编程方式添加到我的,UIToolBar但它似乎似乎没有出现.这就是我对我的代码所做的事情.
- (void) viewWillAppear:(BOOL)animated
{
// Create custom toolbar at top of screen under navigation controller
[matchingSeriesInfoToolBar setFrame:CGRectMake(0, 60, 320, 30)];
matchingSeriesInfoToolBar = [UIToolbar new];
[matchingSeriesInfoToolBar sizeToFit];
CGFloat toolbarHeight = 30;
CGRect mainViewBounds = [[UIScreen mainScreen] applicationFrame];
[matchingSeriesInfoToolBar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds), 0, CGRectGetWidth(mainViewBounds), toolbarHeight)];
matchingSeriesInfoToolBar.tintColor = [UIColor darkGrayColor];
[self.view addSubview:matchingSeriesInfoToolBar];
// Create size of uitableview (to fit toolbar.
[matchingSeriesTableView setFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height - 30)];
[self.view addSubview:matchingSeriesTableView];
// Ad UILabel to the toolbar
UIBarButtonItem *textFieldItem = [[UIBarButtonItem alloc] …Run Code Online (Sandbox Code Playgroud) 我一直在四处寻找正确的方法,从去CFStringRef到NSString在ARC以避免内存泄漏和一些主要的投回答提示:
NSString * string = (__bridge NSString *)cfString;
Run Code Online (Sandbox Code Playgroud)
我在这里使用这种方法,但在分析应用程序时,我仍然在这个小方法中得到内存泄漏[见附图].
所以,我不知道如何解决这个问题.任何人都有解决这个问题的方法吗?
谢谢


所以,显然CFRelease(ext)在返回之前添加了修复泄漏.问题是我不认为我完全理解原因.我以为这行:
NSString * extension = (__bridge NSString*)ext
Run Code Online (Sandbox Code Playgroud)
将取得Core Foundation ext字符串的所有权并处理该版本.任何人都可以解释这里到底发生了什么吗?
ios ×5
iphone ×5
cocoa-touch ×4
objective-c ×4
ios5 ×2
uitableview ×2
cocoa ×1
ios6 ×1
macos ×1
memory-leaks ×1
messageui ×1
nsstream ×1
nsstring ×1
uikit ×1
uilabel ×1
uitoolbar ×1
xcode ×1