小编ste*_*osn的帖子

将NSMutablearray复制到另一个

我正在尝试复制NSMutableArray到另一个但它没有向我显示任何内容UITableView:

NSMutableArray *objectsToAdd= [[NSMutableArray alloc] initWithObjects:@"one",@"two"];

NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:objectsToAdd,nil];

NSMutableArray *list = [[NSMutableArray alloc] init];

[self.list addObjectsFromArray:myArray];
Run Code Online (Sandbox Code Playgroud)

什么都没有出现!怎么了?

它崩溃了我的应用程序,因为我没有对我的nil NSMutableArray如何添加nil?addobject:nil不起作用它崩溃的应用程序:

static NSString * DisclosureButtonCellIdentifier = 
@"DisclosureButtonCellIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: 
                         DisclosureButtonCellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                   reuseIdentifier: DisclosureButtonCellIdentifier]
            autorelease];
}
NSUInteger row = [indexPath row];

NSString *rowString =nil;

rowString = [list objectAtIndex:row];


cell.textLabel.text = rowString;

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
[rowString release];
return cell;
Run Code Online (Sandbox Code Playgroud)

iphone copy nsmutablearray nsarray

5
推荐指数
1
解决办法
3万
查看次数

preg 匹配 php a-zA-Z0-9 和空格

if (preg_match ('/[^a-zA-Z0-9]/i', $getname)) {
Run Code Online (Sandbox Code Playgroud)

我使用这个 preg_match 模式来检查 php 中的字符串是否包含除a-zA-Z0-9. 我想在模式中添加空间...我使用 '/[^a-zA-Z0-9 ]/i'但不起作用...我该怎么做?

我想允许空格,包括 a-zA-Z0-9

php

5
推荐指数
1
解决办法
3万
查看次数

未调用UITextView shouldChangeTextInRange委托

我正在使用此代码来设置我在视图上的uitextview的参数.

_textview=[[UITextView alloc]init];
[_textview setUserInteractionEnabled:FALSE];
_textview.text=@"Write your message";
_textview.textColor=[UIColor lightGrayColor];
_textview.layer.cornerRadius=6;
_textview.contentInset = UIEdgeInsetsZero;
_textview.delegate=self;
Run Code Online (Sandbox Code Playgroud)

我有.h这段代码

IBOutlet UITextView *_textview;
@property(nonatomic,retain) IBOutlet UITextView *_textview;
Run Code Online (Sandbox Code Playgroud)

我已使用界面将插座连接到uitextview.

会发生什么是以下情况:

- (void)textViewDidChange:(UITextView *)inTextView
Run Code Online (Sandbox Code Playgroud)

调用上面的代理但不是以下代理:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementString:(NSString *)string 
Run Code Online (Sandbox Code Playgroud)

为什么会这样?难道我做错了什么?

任何帮助赞赏...

objective-c uitextview

5
推荐指数
2
解决办法
6235
查看次数

iPhone应用程序根据每个国家/地区应用商店本地化并更改应用名称

我已经找到了如何本地化我的应用程序以及如何为用户拥有的每个区域设置更改应用程序的名称,但有人可以告诉我是否可以在应用程序商店中更改应用程序的名称?

我的意思是以下内容.

我的应用在英文应用商店中被称为"helo".如果用户来自意大利并试图在意大利应用程序商店中找到我的应用程序,我希望应用程序名称为"ciao".这可以通过在xcode中使用本地化系统来实现吗?

任何帮助赞赏.

iphone xcode localization

4
推荐指数
1
解决办法
2386
查看次数

目标c中的GMT时区转换

我试图将nsstring转换为nsdate然后再转换为systemtimezone.我的代码是对的吗?任何帮助赞赏.

NSString *str=@"2012-01-15 06:27:42";

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehaviorDefault];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *dateFromString = [dateFormatter dateFromString:str];

NSDate* sourceDate = dateFromString;

NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT-07:00"];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];

NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;

NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease];

bottomLabel2.text=[NSString stringWithFormat:@"- %@ -",destinationDate];
Run Code Online (Sandbox Code Playgroud)

代码结果是2012-01-15 06:27:42 +0000,与源码相同!

objective-c nsdate nstimezone

4
推荐指数
1
解决办法
2万
查看次数

如何使用preg_match检查我的字符串是否包含空格?

我在php中使用此代码来检测字符串是否包含az,AZ,0-9以外的字符.我想检查字符串是否包含任何空格.我应该在模式中添加什么?

if (preg_match ('/[^a-zA-Z0-9]/i', $getmail)) {
    // The string contains characters other than a-z and A-Z and 0-9
}
Run Code Online (Sandbox Code Playgroud)

php regex

2
推荐指数
1
解决办法
8727
查看次数

使用CATransition从右向左和向后过渡?

我有一个uitabbarcontroller,由五个uiview控制器组成.

当我点击第一个uiviewcontroller视图中的按钮时,我想要隐藏uiviewcontroller,并添加一个从右到左过渡的新uiviewcontroller.我已经实现了这一点但是当我点击新视图上的按钮时,应用程序崩溃!按钮没有附加代码.我收到EXEC_BAD_ACCESS错误.

有谁知道为什么会发生这种情况以及如何用新视图克服这个问题?

当我尝试模态视图转换时,视图正常运行.当我尝试使用CATransition时会发生这种情况.我需要CATransition,因为modalview过渡没有从右到左或从左到右的过渡!

任何帮助赞赏!

iphone objective-c ios

2
推荐指数
1
解决办法
3522
查看次数

崩溃了我的应用[NSMutableArray1 removeAllObjects] iphone sdk

我使用此代码来检查我的NSMutableArray中是否存在任何对象,如果是,我将它们全部删除但它崩溃了虽然有对象为什么?

    if([NSMutableArray1 count]==1)
    {
        [poemoptionslist removeAllObjects];
    }



    if ([NSMutableArray1 count]==0)
    {
        [poemoptionslist addObject: final1];
    }
Run Code Online (Sandbox Code Playgroud)

控制台输出

2010-10-18 03:42:13.166 app1 [33398:207] *由于未捕获的异常'NSInternalInconsistencyException'终止应用程序,原因:' - [__ NSCFArray removeObjectAtIndex:]:发送到不可变对象的mutating方法'*第一次调用时调用堆栈:(0 CoreFoundation
0x02e55b99 exceptionPreprocess + 185 1 libobjc.A.dylib
0x02fa540e objc_exception_throw + 47 2 CoreFoundation
0x02e0e238 + [NSException raise:format:arguments:] + 136 3
CoreFoundation
0x02e0e1aa + [NSException raise:format:] + 58 4
CoreFoundation
0x02e4d3c1 - [__NSCFArray removeObjectAtIndex:] + 193 5
CoreFoundation
0x02dfe973 - [NSMutableArray removeAllObjects] + 83 6
poemsoflove
0x0004dc8d - [submitpoem submitpoem:] + 18560 7 UIKit
0x003b77f8 …

iphone nsmutablearray

1
推荐指数
1
解决办法
3636
查看次数

从nsstring iOS中删除空字符

我有这行代码导致我的应用程序崩溃.

 trimmedtext=[NSString stringWithCString:[mycharstring cStringUsingEncoding:[ NSString defaultCStringEncoding ] ] encoding:NSUTF8StringEncoding];
Run Code Online (Sandbox Code Playgroud)

错误是:*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'* + [NSString stringWithCString:encoding:]:NULL cString'

它崩溃了,因为我认为在我的NSString中有一些NULL字符.

NSLog给了我'friendXx',字符串中有一个表情符号!

我怎样才能克服这个问题?

任何帮助赞赏.

正确答案:text = [NSString stringWithCString:[mycharstring UTF8String] encoding:NSUTF8StringEncoding];

objective-c nsstring ios

1
推荐指数
1
解决办法
3283
查看次数

获取使用我的Facebook应用程序的用户列表

我发现有一种方法可以找到我的朋友是我的Facebook应用程序的用户.

$retrobj=$facebook->api(array('method' => 'fql.query', 'query' =>
"SELECT name FROM user WHERE is_app_user = '1' AND uid IN (SELECT uid2
 FROM friend WHERE uid1 = '" . $user. "')"));
Run Code Online (Sandbox Code Playgroud)

上面的查询将显示我的哪些朋友使用我的应用程序.

然后我使用while循环来解析返回的数组.

我的问题是以下......

如果我没有他们的id,有没有办法让所有用户即使他们不是我的朋友使用我的应用程序?

我还没有找到一种方法,这就是为什么我在问是否真的有办法做到这一点.

任何帮助赞赏.

谢谢

facebook facebook-fql facebook-graph-api

1
推荐指数
1
解决办法
1674
查看次数