如何将长阵列存储NSUserDefaults并检索?
以下是我的长阵列的外观:
long *arr;
arr = new long [10];
for(int i = 0 ; i<10 ; i++)
{
arr[i] = i;
}
Run Code Online (Sandbox Code Playgroud)
现在我想将其存储arr到NSUserDefaults稍后然后检索它
我在ios上点击了uibutton,检查了很多文章.但通常,人们使用标签属性作为替代.
但我找到了以下解决方案:
UIButton *btnComLike=[[UIButton alloc] init];
[btnComLike setFrame:CGRectMake(127, 20, 30, 15)];
[btnComLike addTarget:self action:@selector(btnCommentLike_click:) forControlEvents:UIControlEventTouchUpInside];
[btnComLike setTitle:@"Like" forState:UIControlStateNormal];
[btnComLike setTitle:@"my any string value" forState:UIControlStateReserved];
Run Code Online (Sandbox Code Playgroud)
和处理方:
-(void)btnCommentLike_click:(id)sender
{
NSLog(@"%@",[sender titleForState:UIControlStateReserved]);
}
Run Code Online (Sandbox Code Playgroud)
这是一个可行的解决方案吗?我认为一方面就是利用这种状态UIControlStateReserved.
或者使用这种技术有任何缺点吗?
如果有,请告诉我有什么问题?
我的iOS应用程序解析从远程服务器获取的xml(我不能以任何方式影响).当它遇到如下所示的xml标记时:
<tag a="x" b="y" c="z">
this is a
<aabb/>
content
<ccdd/>
string
</tag>
Run Code Online (Sandbox Code Playgroud)
它只解析内容的第一部分("这是一个"),而忽略了这些单个标记之后的所有内容.无论这些单个标签中有多少个跟随,如果它只有一个标签,它也会跳过其余标签.我没有真正得到这种行为,是否有解释或方法来克服这个问题?
import UIKit
class ViewController: UIViewController, UITableViewDataSource,UITableViewDelegate {
@IBOutlet weak var label: UILabel!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var tableView1: UITableView!
let element = ["Sports": #imageLiteral(resourceName: "ios"),"Grocery":#imageLiteral(resourceName: "ios"),"Cosmetics":#imageLiteral(resourceName: "ios")]
override func viewDidLoad() {
super.viewDidLoad()
tableView1.delegate = self
tableView1.dataSource = self
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { …Run Code Online (Sandbox Code Playgroud) 我有一个名为的图像my-image.我可以将此图像保存到应用程序包吗?如果是,您可以向我提供代码或路径吗?
截至目前,我有以下代码 -
NSData * imageData = UIImagePNGRepresentation(userSavedImage); //convert image into .png format.
NSFileManager * fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
NSString * documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
NSString * fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",txtImageName.text]]; //add our image to the path
[fileManager createFileAtPath:fullPath contents:imageData …Run Code Online (Sandbox Code Playgroud) 我想动态生成按钮.下面的代码生成2个按钮.但是我怎样才能编写一个循环来生成批量(100或1000)按钮.
- (void)viewDidLoad
{
//allocate the view
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
//set the view's background color
self.view.backgroundColor = [UIColor whiteColor];
//create the buttons
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//set the position of the button
button.frame = CGRectMake(100, 170, 100, 30);
button1.frame = CGRectMake(200, 170, 100, 30);
//set the button's title
[button setTitle:@"Click Me!" forState:UIControlStateNormal];
[button1 setTitle:@"Click!" forState:UIControlStateNormal];
//listen for clicks
[button addTarget:self action:@selector(buttonPressed)
forControlEvents:UIControlEventTouchUpInside];
[button1 addTarget:self action:@selector(buttonPressed)
forControlEvents:UIControlEventTouchUpInside];
//add the button to …Run Code Online (Sandbox Code Playgroud) 标签位于屏幕中央(或下方),iphone 4.3不显示.但iphone与iOS 5.0显示.全部由IB制造.
UPD :(代码)
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.view.backgroundColor = [UIColor blackColor];
[scroll setContentSize:CGSizeMake(320, 700)];
scroll.frame = CGRectMake(0, 0, 320, 460);
}
return self;
}
Run Code Online (Sandbox Code Playgroud) 我是iOS新手。我想在iOS中解析这种类型的JSON响应。这是贝宝的回应。我想访问所有数据并制作字典并将其存储以用于其他目的。如何访问所有字段并将其设置为字典?
{
client = {
environment = sandbox;
"paypal_sdk_version" = "2.0.1";
platform = iOS;
"product_name" = "PayPal iOS SDK";
};
response = {
"create_time" = "2014-04-12T05:15:25Z";
id = "PAY-72670124ZX823130UKNEMX3I";
intent = sale;
state = approved;
};
"response_type" = payment;
}
Run Code Online (Sandbox Code Playgroud) 任何人都可以帮助我,我需要一个正则表达式密码验证.
条件:密码最多为8个字符数字或字母,至少有一个特殊字符
提前致谢.
objective-c ×8
cocoa-touch ×7
ios ×5
app-bundle ×1
dictionary ×1
ios4 ×1
iphone ×1
json ×1
nsxmlparser ×1
regex ×1
swift ×1
uibutton ×1
uilabel ×1
uiscrollview ×1
uitableview ×1