Gowhich

Durban's Blog

关于表格的排序是使用了NSComparisonResult这个方法,很简单的,只要自己定义几个方法,就可以了

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@interface NSString (sortingExtension)

@end

@implementation NSString (sortingExtension)
- (NSComparisonResult) reverseCompare: (NSString *) aString
{
return -1 * [self caseInsensitiveCompare:aString];
}

- (NSComparisonResult) lengthCompare: (NSString *) aString
{
if (self.length == aString.length) return NSOrderedSame;
if (self.length > aString.length) return NSOrderedDescending;
return NSOrderedAscending;
}
@end

自己写个方法,然后封装到里面就好了,关于NSString (sortingExtension)这个名字,没研究出啥道道来,只是觉得奇怪

我迫于喜欢IOS5的storyboard,于是此篇也是用了storyboard

SortTableViewController.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// SortTableViewController.h
// SortTable
//
// Created by david on 13-8-7.
// Copyright (c) 2013年 WalkerFree. All rights reserved.
//

#import <UIKit/UIKit.h>

#define COOKBOOK_PURPLE_COLOR [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f]
#define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target:self action:SELECTOR] autorelease]
#define SYSBARBUTTON(ITEM, SELECTOR) [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:ITEM target:self action:SELECTOR] autorelease]
#define CRAYON_NAME(CRAYON) [[CRAYON componentsSeparatedByString:@"#"] objectAtIndex:0]
#define CRAYON_COLOR(CRAYON) [self getColor:[[CRAYON componentsSeparatedByString:@"#"] lastObject]]


@interface NSString (sortingExtensionFF)

@end

@implementation NSString (sortingExtensionFF)
- (NSComparisonResult) reverseCompare: (NSString *) aString
{
return -1 * [self caseInsensitiveCompare:aString];
}

- (NSComparisonResult) lengthCompare: (NSString *) aString
{
if (self.length == aString.length) return NSOrderedSame;
if (self.length > aString.length) return NSOrderedDescending;
return NSOrderedAscending;
}
@end


@interface SortTableViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tableView;

@property (retain) NSArray *items;

@end

SortTableViewController.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// SortTableViewController.m
// SortTable
//
// Created by david on 13-8-7.
// Copyright (c) 2013年 WalkerFree. All rights reserved.
//

#import "SortTableViewController.h"

@interface SortTableViewController ()

@end

@implementation SortTableViewController

@synthesize items;
@synthesize tableView;

- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR;

self.tableView.delegate = self;
self.tableView.dataSource = self;

NSError *error;
NSString *pathname = [[NSBundle mainBundle] pathForResource:@"content" ofType:@"text"];

self.items = [[NSString stringWithContentsOfFile:pathname
encoding:NSUTF8StringEncoding
error:&error] componentsSeparatedByString:@"\n"];

UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:[@"Ascending Descending Length" componentsSeparatedByString:@" "]];
seg.segmentedControlStyle = UISegmentedControlStyleBar;
seg.selectedSegmentIndex = 0;
[seg addTarget:self action:@selector(updateSort:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = seg;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewCell Method
- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
return items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCellStyle style = UITableViewCellStyleDefault;
UITableViewCell *cell = [tView dequeueReusableCellWithIdentifier:@"BaseCell"];
if (!cell) cell = [[UITableViewCell alloc] initWithStyle:style reuseIdentifier:@"BaseCell"];
NSString *crayon = [items objectAtIndex:indexPath.row];
cell.textLabel.text = CRAYON_NAME(crayon);
if (![CRAYON_NAME(crayon) hasPrefix:@"White"])
cell.textLabel.textColor = CRAYON_COLOR(crayon);
else
cell.textLabel.textColor = [UIColor blackColor];
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *crayon = [self.items objectAtIndex:indexPath.row];
self.navigationController.navigationBar.tintColor = CRAYON_COLOR(crayon);
}

- (void) updateSort: (UISegmentedControl *) seg
{
if (seg.selectedSegmentIndex == 0)
self.items = [self.items sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
else if (seg.selectedSegmentIndex == 1)
self.items = [self.items sortedArrayUsingSelector:@selector(reverseCompare:)];
else if (seg.selectedSegmentIndex == 2)
self.items = [self.items sortedArrayUsingSelector:@selector(lengthCompare:)];

[self.tableView reloadData];
}



- (UIColor *) getColor: (NSString *) hexColor
{
unsigned int red, green, blue;
NSRange range;
range.length = 2;

range.location = 0;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];
range.location = 2;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green];
range.location = 4;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue];

return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green/255.0f) blue:(float)(blue/255.0f) alpha:1.0f];
}

@end

以上代码绝对支持ARC,时代是新的,代码的创新,跟着创新走吧,别烦恼更新太快,为了项目的最新,为了能够展示更好的项目,更新并不是什么坏事。

欢迎大家对我博客的支持,最近无意间发现自己的博客的代码高亮出现了问题,原因是自己在做搜索的时候,为了减少js的加载,将某个layout模块删掉了,导致最后出问题自己还不知道,今天改的时候,更是不知道该如何改了,因为忘记了之前自己是如何添加这段代码的啦。不过咱就是写代码的,重写会有更多的收获的。

我就贴出 一下自己的css代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter {
background-color: #34495E !important;
border-radius: 5px;
}
.syntaxhighlighter .line.alt1 {
background-color: #34495E !important;
}
.syntaxhighlighter .line.alt2 {
background-color: #34495E !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #34495E !important;
}
.syntaxhighlighter .line.highlighted.number {
color: white !important;
}
.syntaxhighlighter table{
margin: 1px 0 !important;
}
.syntaxhighlighter table caption {
color: #f8f8f8 !important;
}
.syntaxhighlighter .gutter {
color: white !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #1ABC9C !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #41a83e !important;
color: #0a2b1d !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #96dd3b !important;
background: black !important;
border: 1px solid #41a83e !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #96dd3b !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: white !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #41a83e !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #ffe862 !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: #f8f8f8 !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #336442 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #9df39f !important;
background-color: #34495E;
}
.syntaxhighlighter .keyword {
color: #96dd3b !important;
}
.syntaxhighlighter .preprocessor {
color: #91bb9e !important;
}
.syntaxhighlighter .variable {
color: #ffaa3e !important;
}
.syntaxhighlighter .value {
color: #f7e741 !important;
}
.syntaxhighlighter .functions {
color: #ffaa3e !important;
}
.syntaxhighlighter .constants {
color: #e0e8ff !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #96dd3b !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: #eb939a !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: #91bb9e !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #edef7d !important;
}

.syntaxhighlighter .comments {
font-style: italic !important;
background-color: #34495E;
}
.syntaxhighlighter .keyword {
font-weight: bold !important;
}

code{
background-color: #34495E;
border:1px solid #34495E;
}

千万注意的是,不要光之引入此css代码,还有一个核心的代码也一定要引入进来,不然会出现更乱的情况

1
2
<link href="/syntaxhighlighter/styles/shCore.css" rel="stylesheet">    
<link href="/syntaxhighlighter/styles/shThemeFlatUI.css" rel="stylesheet">

最近一个项目,由于要使用腾讯的登录接口,于是就申请了一个,下来了PHP版本的SDK,拿回来,用起来真是麻烦,麻烦的事情是,好就三个类,写在了三个文件中,最后我在QEEPHP的框架中调用,老是报错,说循环次数超过100次,于是自己改装了一下,提示一下,这个是可是QEEPHP版本的。如果是其他的框架的话,就不知道了,不过懂OOP的,基本上拿过去也是可以使用的。

我把代码贴到下面,大家喜欢的就拿去用吧

核心类库:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
<?php
/* PHP SDK
* @version 2.0.0
* @author xx@xx
* @copyright © 2013, Tencent Corporation. All rights reserved.
*/
define("ROOT",dirname(dirname(__FILE__))."/");
define("CLASS_PATH",ROOT."class/");

class Oauth{

const VERSION = "2.0";
const GET_AUTH_CODE_URL = "https://graph.qq.com/oauth2.0/authorize";
const GET_ACCESS_TOKEN_URL = "https://graph.qq.com/oauth2.0/token";
const GET_OPENID_URL = "https://graph.qq.com/oauth2.0/me";

protected $recorder;
public $urlUtils;
protected $error;


public function __construct(){
$this->recorder = new Recorder();
$this->urlUtils = new URL();
$this->error = new ErrorCase();
}

public function qq_login(){

$appid = $this->recorder->readInc("appid");
$callback = $this->recorder->readInc("callback");
$scope = $this->recorder->readInc("scope");

//-------生成唯一随机串防CSRF攻击
$state = md5(uniqid(rand(), TRUE));
$this->recorder->write('state',$state);

//-------构造请求参数列表
$keysArr = array(
"response_type" => "code",
"client_id" => $appid,
"redirect_uri" => $callback,
"state" => $state,
"scope" => $scope
);

$login_url = $this->urlUtils->combineURL(self::GET_AUTH_CODE_URL, $keysArr);

header("Location:$login_url");
}

public function qq_callback(){
$state = $this->recorder->read("state");

//--------验证state防止CSRF攻击
if($_GET['state'] != $state){
// $this->error->showError("30001");
return false;
}

//-------请求参数列表
$keysArr = array(
"grant_type" => "authorization_code",
"client_id" => $this->recorder->readInc("appid"),
"redirect_uri" => urlencode($this->recorder->readInc("callback")),
"client_secret" => $this->recorder->readInc("appkey"),
"code" => $_GET['code']
);

//------构造请求access_token的url
$token_url = $this->urlUtils->combineURL(self::GET_ACCESS_TOKEN_URL, $keysArr);
$response = $this->urlUtils->get_contents($token_url);

if(strpos($response, "callback") !== false){

$lpos = strpos($response, "(");
$rpos = strrpos($response, ")");
$response = substr($response, $lpos + 1, $rpos - $lpos -1);
$msg = json_decode($response);

if(isset($msg->error)){
// $this->error->showError($msg->error, $msg->error_description);
return false;
}
}

$params = array();
parse_str($response, $params);

$this->recorder->write("access_token", $params["access_token"]);
return $params["access_token"];

}

public function get_openid(){

//-------请求参数列表
$keysArr = array(
"access_token" => $this->recorder->read("access_token")
);

$graph_url = $this->urlUtils->combineURL(self::GET_OPENID_URL, $keysArr);
$response = $this->urlUtils->get_contents($graph_url);

//--------检测错误是否发生
if(strpos($response, "callback") !== false){

$lpos = strpos($response, "(");
$rpos = strrpos($response, ")");
$response = substr($response, $lpos + 1, $rpos - $lpos -1);
}

$user = json_decode($response);
if(isset($user->error)){
// $this->error->showError($user->error, $user->error_description);
return false;
}

//------记录openid
$this->recorder->write("openid", $user->openid);
return $user->openid;

}
}

/**
* PHP SDK
* @version 2.0.0
* @author xx@xx
* @copyright © 2013, Tencent Corporation. All rights reserved.
*/
class Recorder{
private static $data;
private $inc;
private $error;

public function __construct(){
$this->error = new ErrorCase();

//-------读取配置文件
$incFileContents = file_get_contents(ROOT."comm/inc.php");
$this->inc = json_decode($incFileContents);
if(empty($this->inc)){
$this->error->showError("20001");
}

if(empty($_SESSION['QC_userData'])){
self::$data = array();
}else{
self::$data = $_SESSION['QC_userData'];
}

}

public function write($name,$value){
self::$data[$name] = $value;
}

public function read($name){
if(empty(self::$data[$name])){
return null;
}else{
return self::$data[$name];
}
}

public function readInc($name){
if(empty($this->inc->$name)){
return null;
}else{
return $this->inc->$name;
}
}

public function delete($name){
unset(self::$data[$name]);
}

function __destruct(){
$_SESSION['QC_userData'] = self::$data;
}
}

/**
* PHP SDK
* @version 2.0.0
* @author xx@xx
* @copyright © 2013, Tencent Corporation. All rights reserved.
*/
class URL{
private $error;

public function __construct(){
$this->error = new ErrorCase();
}

/**
* combineURL
* 拼接url
* @param string $baseURL 基于的url
* @param array $keysArr 参数列表数组
* @return string 返回拼接的url
*/
public function combineURL($baseURL,$keysArr){
$combined = $baseURL."?";
$valueArr = array();

foreach($keysArr as $key => $val){
$valueArr[] = "$key=$val";
}

$keyStr = implode("&",$valueArr);
$combined .= ($keyStr);

return $combined;
}

/**
* get_contents
* 服务器通过get请求获得内容
* @param string $url 请求的url,拼接后的
* @return string 请求返回的内容
*/
public function get_contents($url){
if (ini_get("allow_url_fopen") == "1") {
$response = file_get_contents($url);
}else{
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
}

//-------请求为空
if(empty($response)){
$this->error->showError("50001");
}

return $response;
}

/**
* get
* get方式请求资源
* @param string $url 基于的baseUrl
* @param array $keysArr 参数列表数组
* @return string 返回的资源内容
*/
public function get($url, $keysArr){
$combined = $this->combineURL($url, $keysArr);
return $this->get_contents($combined);
}

/**
* post
* post方式请求资源
* @param string $url 基于的baseUrl
* @param array $keysArr 请求的参数列表
* @param int $flag 标志位
* @return string 返回的资源内容
*/
public function post($url, $keysArr, $flag = 0){

$ch = curl_init();
if(! $flag) curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $keysArr);
curl_setopt($ch, CURLOPT_URL, $url);
$ret = curl_exec($ch);

curl_close($ch);
return $ret;
}
}

/**
* @brief ErrorCase类,封闭异常
*/
class ErrorCase{

private $errorMsg;
private $recorder;
public function __construct(){
$this->errorMsg = array(
"20001" => "<h2>配置文件损坏或无法读取,请重新执行intall</h2>",
"30001" => "<h2>The state does not match. You may be a victim of CSRF.</h2>",
"50001" => "<h2>可能是服务器无法请求https协议</h2>可能未开启curl支持,请尝试开启curl支持,重启web服务器,如果问题仍未解决,请联系我们"
);
}

/**
* showError
* 显示错误信息
* @param int $code 错误代码
* @param string $description 描述信息(可选)
*/
public function showError($code, $description = '$'){
$this->recorder = new Recorder();
if(! $this->recorder->readInc("errorReport")){
die();//die quietly
}


echo "<meta charset=\"UTF-8\">";
if($description == "$"){
die($this->errorMsg[$code]);
}else{
echo "<h3>error:</h3>$code";
echo "<h3>msg :</h3>$description";
exit();
}
}
public function showTips($code, $description = '$'){

}

public function __destruct() {
unset($this->recorder);
}
}

/**
* @brief QC类,api外部对象,调用接口全部依赖于此对象
*/
class QC extends Oauth{
private $kesArr, $APIMap;

/**
* _construct
*
* 构造方法
* @access public
* @since 5
* @param string $access_token access_token value
* @param string $openid openid value
* @return Object QC
*/
public function __construct($access_token = "", $openid = ""){
parent::__construct();

//如果access_token和openid为空,则从session里去取,适用于demo展示情形
if($access_token === "" || $openid === ""){
$this->keysArr = array(
"oauth_consumer_key" => (int)$this->recorder->readInc("appid"),
"access_token" => $this->recorder->read("access_token"),
"openid" => $this->recorder->read("openid")
);
}else{
$this->keysArr = array(
"oauth_consumer_key" => (int)$this->recorder->readInc("appid"),
"access_token" => $access_token,
"openid" => $openid
);
}

//初始化APIMap
/*
* 加#表示非必须,无则不传入url(url中不会出现该参数), "key" => "val" 表示key如果没有定义则使用默认值val
* 规则 array( baseUrl, argListArr, method)
*/
$this->APIMap = array(


/* qzone */
"add_blog" => array(
"https://graph.qq.com/blog/add_one_blog",
array("title", "format" => "json", "content" => null),
"POST"
),
"add_topic" => array(
"https://graph.qq.com/shuoshuo/add_topic",
array("richtype","richval","con","#lbs_nm","#lbs_x","#lbs_y","format" => "json", "#third_source"),
"POST"
),
"get_user_info" => array(
"https://graph.qq.com/user/get_user_info",
array("format" => "json"),
"GET"
),
"add_one_blog" => array(
"https://graph.qq.com/blog/add_one_blog",
array("title", "content", "format" => "json"),
"GET"
),
"add_album" => array(
"https://graph.qq.com/photo/add_album",
array("albumname", "#albumdesc", "#priv", "format" => "json"),
"POST"
),
"upload_pic" => array(
"https://graph.qq.com/photo/upload_pic",
array("picture", "#photodesc", "#title", "#albumid", "#mobile", "#x", "#y", "#needfeed", "#successnum", "#picnum", "format" => "json"),
"POST"
),
"list_album" => array(
"https://graph.qq.com/photo/list_album",
array("format" => "json")
),
"add_share" => array(
"https://graph.qq.com/share/add_share",
array("title", "url", "#comment","#summary","#images","format" => "json","#type","#playurl","#nswb","site","fromurl"),
"POST"
),
"check_page_fans" => array(
"https://graph.qq.com/user/check_page_fans",
array("page_id" => "314416946","format" => "json")
),
/* wblog */

"add_t" => array(
"https://graph.qq.com/t/add_t",
array("format" => "json", "content","#clientip","#longitude","#compatibleflag"),
"POST"
),
"add_pic_t" => array(
"https://graph.qq.com/t/add_pic_t",
array("content", "pic", "format" => "json", "#clientip", "#longitude", "#latitude", "#syncflag", "#compatiblefalg"),
"POST"
),
"del_t" => array(
"https://graph.qq.com/t/del_t",
array("id", "format" => "json"),
"POST"
),
"get_repost_list" => array(
"https://graph.qq.com/t/get_repost_list",
array("flag", "rootid", "pageflag", "pagetime", "reqnum", "twitterid", "format" => "json")
),
"get_info" => array(
"https://graph.qq.com/user/get_info",
array("format" => "json")
),
"get_other_info" => array(
"https://graph.qq.com/user/get_other_info",
array("format" => "json", "#name", "fopenid")
),
"get_fanslist" => array(
"https://graph.qq.com/relation/get_fanslist",
array("format" => "json", "reqnum", "startindex", "#mode", "#install", "#sex")
),
"get_idollist" => array(
"https://graph.qq.com/relation/get_idollist",
array("format" => "json", "reqnum", "startindex", "#mode", "#install")
),
"add_idol" => array(
"https://graph.qq.com/relation/add_idol",
array("format" => "json", "#name-1", "#fopenids-1"),
"POST"
),
"del_idol" => array(
"https://graph.qq.com/relation/del_idol",
array("format" => "json", "#name-1", "#fopenid-1"),
"POST"
),
/* pay */

"get_tenpay_addr" => array(
"https://graph.qq.com/cft_info/get_tenpay_addr",
array("ver" => 1,"limit" => 5,"offset" => 0,"format" => "json")
)
);
}

//调用相应api
private function _applyAPI($arr, $argsList, $baseUrl, $method){
$pre = "#";
$keysArr = $this->keysArr;

$optionArgList = array();//一些多项选填参数必选一的情形
foreach($argsList as $key => $val){
$tmpKey = $key;
$tmpVal = $val;

if(!is_string($key)){
$tmpKey = $val;

if(strpos($val,$pre) === 0){
$tmpVal = $pre;
$tmpKey = substr($tmpKey,1);
if(preg_match("/-(\d$)/", $tmpKey, $res)){
$tmpKey = str_replace($res[0], "", $tmpKey);
$optionArgList[$res[1]][] = $tmpKey;
}
}else{
$tmpVal = null;
}
}

//-----如果没有设置相应的参数
if(!isset($arr[$tmpKey]) || $arr[$tmpKey] === ""){

if($tmpVal == $pre){//则使用默认的值
continue;
}else if($tmpVal){
$arr[$tmpKey] = $tmpVal;
}else{
if($v = $_FILES[$tmpKey]){

$filename = dirname($v['tmp_name'])."/".$v['name'];
move_uploaded_file($v['tmp_name'], $filename);
$arr[$tmpKey] = "@$filename";

}else{
$this->error->showError("api调用参数错误","未传入参数$tmpKey");
}
}
}

$keysArr[$tmpKey] = $arr[$tmpKey];
}
//检查选填参数必填一的情形
foreach($optionArgList as $val){
$n = 0;
foreach($val as $v){
if(in_array($v, array_keys($keysArr))){
$n ++;
}
}

if(! $n){
$str = implode(",",$val);
$this->error->showError("api调用参数错误",$str."必填一个");
}
}

if($method == "POST"){
if($baseUrl == "https://graph.qq.com/blog/add_one_blog") $response = $this->urlUtils->post($baseUrl, $keysArr, 1);
else $response = $this->urlUtils->post($baseUrl, $keysArr, 0);
}else if($method == "GET"){
$response = $this->urlUtils->get($baseUrl, $keysArr);
}

return $response;

}

/**
* _call
* 魔术方法,做api调用转发
* @param string $name 调用的方法名称
* @param array $arg 参数列表数组
* @since 5.0
* @return array 返加调用结果数组
*/
public function __call($name,$arg){
//如果APIMap不存在相应的api
if(empty($this->APIMap[$name])){
$this->error->showError("api调用名称错误","不存在的API: <span style='color:red;'>$name</span>");
}

//从APIMap获取api相应参数
$baseUrl = $this->APIMap[$name][0];
$argsList = $this->APIMap[$name][1];
$method = isset($this->APIMap[$name][2]) ? $this->APIMap[$name][2] : "GET";

if(empty($arg)){
$arg[0] = null;
}

//对于get_tenpay_addr,特殊处理,php json_decode对\xA312此类字符支持不好
if($name != "get_tenpay_addr"){
$response = json_decode($this->_applyAPI($arg[0], $argsList, $baseUrl, $method));
$responseArr = $this->objToArr($response);
}else{
$responseArr = $this->simple_json_parser($this->_applyAPI($arg[0], $argsList, $baseUrl, $method));
}


//检查返回ret判断api是否成功调用
if($responseArr['ret'] == 0){
return $responseArr;
}else{
$this->error->showError($response->ret, $response->msg);
}

}

//php 对象到数组转换
private function objToArr($obj){
if(!is_object($obj) && !is_array($obj)) {
return $obj;
}
$arr = array();
foreach($obj as $k => $v){
$arr[$k] = $this->objToArr($v);
}
return $arr;
}


/**
* get_access_token
* 获得access_token
* @param void
* @since 5.0
* @return string 返加access_token
*/
public function get_access_token(){
return $this->recorder->read("access_token");
}

//简单实现json到php数组转换功能
private function simple_json_parser($json){
$json = str_replace("{","",str_replace("}","", $json));
$jsonValue = explode(",", $json);
$arr = array();
foreach($jsonValue as $v){
$jValue = explode(":", $v);
$arr[str_replace('"',"", $jValue[0])] = (str_replace('"', "", $jValue[1]));
}
return $arr;
}
}

别忘记了还有一个是实现的类库:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php 
/**
* 腾讯接口操作类
* @version 2.0
*/
require_once(Q::ini('app_config/ROOT_DIR').'/app/helper/qq/class/Oauth.class.php');
class Helper_QQ{
/**
* 登陆接口
*/
static public function qqLogin(){
$handle = new QC();
$handle->qq_login();
}

/**
* 回调接口
* @return String
*/
static public function qqCallback(){
$handle = new QC();
return $handle->qq_callback();
}

/**
* 获取openid接口
* @return type
*/
static public function qqOpenid(){
$handle = new QC();
return $handle->get_openid();
}

/**
* 获取用户信息接口
* @param String $accessToken
* @param String $openId
* @return String
*/
static public function qqUserInfo($accessToken,$openId){
$handle = new QC($accessToken,$openId);
return $handle->get_info();
}
}
?>

使用的方法就是,在控制器里面直接调用啦,

1
2
3
4
Helper_QQ::qqLogin();//登录
$accessToken = Helper_QQ::qqCallback();//在回调里面使用
$openId = Helper_QQ::qqOpenid();//在回调里面使用
Helper_QQ::qqUserInfo($accessToken, $openId);//在回调里面使用

还有一个就是配置文件(inc.php)这里面是json的字符串

1
{"appid":"xxxxxxxx","appkey":"xxxxxxxxxxxxxxxx","callback":"www.test.com/callback/type/qq","scope":"get_user_info,add_share,list_album,add_album,upload_pic,add_topic,add_one_blog,add_weibo,check_page_fans,add_t,add_pic_t,del_t,get_repost_list,get_info,get_other_info,get_fanslist,get_idolist,add_idol,del_idol,get_tenpay_addr","errorReport":true,"storageType":"file","host":"localhost","user":"root","password":"root","database":"test"}

代码我放在github上啦《github

之前使用php输出html代码的时候,可以使用二维数组,这样子就可以进行循环输出html,但是在django中,有了一个更牛逼的方法就是,不需要自己去分组啦,直接使用计数器就很方便的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<div id='container'>
{% for item in items %}
{% if forloop.counter0|divisibleby:"4" %}
<ul class="thumbnails">
{% endif %}
<li class="listitem span3">
<div class="thumbnail">
<a target='_blank' title='{{ item.title }}' href='{% url gifts_detail item.id %}'>
<img alt="{{ item.title }}" src="{{ MEDIA_URL }}{{ item.large_image }}" width="192" height="288">
</a>
<section style="margin-top:10px">
<div class="progress progress-striped active progress-success">
<div class="bar" style="width: {% widthratio item.feeling item.feeling|add:item.no_feeling 100 %}%;"></div>
</div>
</section>
<section style="margin-top:10px">
<div class="progress progress-striped active progress-danger">
<div class="bar" style="width: {% widthratio item.no_feeling item.feeling|add:item.no_feeling 100 %}%;"></div>
</div>
</section>
<section class="" style="margin-top:10px">
<a class="btn btn-primary have_feeling" href="#" onclick="Dajaxice.walkerfree.feeling(feeling_callback, {'id':'{{ item.id }}','type':'gift'});return false;">有感觉</a>
<a class="btn btn-primary no_feeling" href="#" onclick="Dajaxice.walkerfree.no_feeling(no_feeling_callback,{'id':'{{ item.id }}','type':'gift'});return false;">没感觉</a>
<input type='hidden' value='gift' name='type'>
</section>
</div>
</li>
{% if forloop.last or forloop.counter|divisibleby:"4" %}
</ul>
{% endif %}
{% endfor %}
</div>

完全可以按照自己的分组需求进行分组输出啦

In order for your app to take full advantage of the iPhone 4 Retina Display, you’ll need to add 2x resources to your iPhone project.

If you’re using SVN to manage your files, you’ll be faced with something pretty annoying:

1
2
$ svn add xunYi7/library/images/[email protected]
svn: warning: 'xunYi7/library/images/blackArrow' not found

This was incredibly frustrating for me, no matter how I tried to escape it: single quotes, double quotes, backslashes, etc. SVN refused to add.

This is due to internal path recognizers in SVN. It expects the last at symbol to specify a revision. This is easily corrected by adding an at symbol to the end of your file:

1
2
$ svn add xunYi7/library/images/[email protected]@
A (bin) xunYi7/library/images/[email protected]

You’ll still need to manually add each resource, but it’s better than nothing. You could also use an IDE like Cornerstone, but I prefer the SVN CLI way of managing SVN.

这种项目中,svn也是有对应的解决方案的

最近想实现一个功能,就是在浏览器中输入url地址,实现app的跳转,实现这样的功能并不麻烦,通过将网上一些相关教程汇总以后就写了下面的教程分享。

实现效果如下,在浏览器中输入“Lover://”之后就会打开这个程序,打开后程序中会显示跳转过来的链接地址。

第一步:配置info.plist

其中URL identifier 可以随便取,URL Schemes 就是实现跳转URL协议的名称(可以多个)


然后,在视图控制器中加入代码,用于显示跳转过来的地址:

第二步:代码实现过程

在viewController里面添加一个显示信息的函数+(void) showMessage:(NSString *)message;

1
2
3
4
+(void) showMessage:(NSString *)message{

NSLog(@"Message : %@",message);
}

在delegate里面调用一下

首先需要实现一个方法:-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url

1
2
3
4
5
6
7
8
9
10
-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url{
if(!url){
return NO;
}

NSString *urlString = [url absoluteString];
[SafariToAppViewController showMessage:urlString];

return YES;
}

就完成了这个看似很酷的功能,至于参数传递的问题,我这里做了一个颜色的取值

实现代码如下(在delegate中实现):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{

// You should be extremely careful when handling URL requests.
// Take steps to validate the URL before handling it.

// Check if the incoming URL is nil.
if (!url)
return NO;

// Invoke our helper method to parse the incoming URL and extact the color
// to display.
UIColor *launchColor = [self extractColorFromLaunchURL:url];
// Stop if the url could not be parsed.
if (!launchColor)
return NO;

[SafariToAppViewController showMessage:[NSString stringWithFormat:@"%@",launchColor]];

return YES;

}

- (UIColor*)extractColorFromLaunchURL:(NSURL*)url
{
// Hexadecimal color codes begin with a number sign (#) followed by six
// hexadecimal digits. Thus, a color in this format is represented by
// three bytes (the number sign is ignored). The value of each byte
// corresponds to the intensity of either the red, blue or green color
// components, in that order from left to right.
// Additionally, there is a shorthand notation with the number sign (#)
// followed by three hexadecimal digits. This notation is expanded to
// the six digit notation by doubling each digit: #123 becomes #112233.


// Convert the incoming URL into a string. The '#' character will be percent
// escaped. That must be undone.
NSString *urlString = [[url absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// Stop if the conversion failed.
if (!urlString)
return nil;

// Create a regular expression to locate hexadecimal color codes in the
// incoming URL.
// Incoming URLs can be malicious. It is best to use vetted technology,
// such as NSRegularExpression, to handle the parsing instead of writing
// your own parser.
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"#[0-9a-f]{3}([0-9a-f]{3})?"
options:NSRegularExpressionCaseInsensitive
error:&error];

// Check for any error returned. This can be a result of incorrect regex
// syntax.
if (error)
{
NSLog(@"%@", error);
return nil;
}

// Extract all the matches from the incoming URL string. There must be at least
// one for the URL to be valid (though matches beyond the first are ignored.)
NSArray *regexMatches = [regex matchesInString:urlString options:0 range:NSMakeRange(0, urlString.length)];
if (regexMatches.count < 1)
return nil;

// Extract the first matched string
NSString *matchedString = [urlString substringWithRange:[regexMatches[0] range]];

// At this point matchedString will look similar to either #FFF or #FFFFFF.
// The regular expression has guaranteed that matchedString will be no longer
// than seven characters.

// Extract an ASCII c string from matchedString. The '#' character should not be
// included.
const char *matchedCString = [[matchedString substringFromIndex:1] cStringUsingEncoding:NSASCIIStringEncoding];

// Convert matchedCString into an integer.
unsigned long hexColorCode = strtoul(matchedCString, NULL, 16);

CGFloat red, green, blue;

if (matchedString.length-1 > 3)
// If the color code is in six digit notation...
{
// Extract each color component from the integer representation of the
// color code. Each component has a value of [0-255] which must be
// converted into a normalized float for consumption by UIColor.
red = ((hexColorCode & 0x00FF0000) >> 16) / 255.0f;
green = ((hexColorCode & 0x0000FF00) >> 8) / 255.0f;
blue = (hexColorCode & 0x000000FF) / 255.0f;
}
else
// The color code is in shorthand notation...
{
// Extract each color component from the integer representation of the
// color code. Each component has a value of [0-255] which must be
// converted into a normalized float for consumption by UIColor.
red = (((hexColorCode & 0x00000F00) >> 8) | ((hexColorCode & 0x00000F00) >> 4)) / 255.0f;
green = (((hexColorCode & 0x000000F0) >> 4) | (hexColorCode & 0x000000F0)) / 255.0f;
blue = ((hexColorCode & 0x0000000F) | ((hexColorCode & 0x0000000F) << 4)) / 255.0f;
}

// Create and return a UIColor object with the extracted components.
return [UIColor colorWithRed:red green:green blue:blue alpha:1.0f];
}

关于视图的翻转效果,最近我稍微的做了一下研究

主要的是使用了一个函数

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);

还是演示一下吧,我这里是使用的storyboard

FlipViewViewController.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//
// FlipViewViewController.h
// FlipView
//
// Created by david on 13-8-4.
// Copyright (c) 2013年 WalkerFree. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface FlipViewViewController : UIViewController

@property (strong, nonatomic) UIView *frontView;
@property (strong, nonatomic) UIView *backView;
@property (nonatomic) BOOL goingToFrontView;

@property (strong, nonatomic) IBOutlet UIBarButtonItem *FlipButton;
- (IBAction)FlipButtonAction:(id)sender;

@end

FlipViewViewController.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// FlipViewViewController.m
// FlipView
//
// Created by david on 13-8-4.
// Copyright (c) 2013年 WalkerFree. All rights reserved.
//

#import "FlipViewViewController.h"

@interface FlipViewViewController ()

@end


@implementation FlipViewViewController

@synthesize frontView;
@synthesize backView;
@synthesize FlipButton;
@synthesize goingToFrontView;

- (void)viewDidLoad
{
[super viewDidLoad];

self.frontView = [[UIView alloc] initWithFrame:self.view.frame];
self.backView = [[UIView alloc] initWithFrame:self.view.frame];
}

-(void) viewWillAppear:(BOOL)animated{
self.FlipButton.title = @"前视图";
self.goingToFrontView = YES;

[self initFrontViewBackgroundColor];
[self initBackViewBackGroundColor];

[self.view addSubview:self.frontView];
[self.view addSubview:self.backView];


}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)FlipButtonAction:(id)sender {
self.goingToFrontView = !self.goingToFrontView;

UIView *fromView = self.goingToFrontView ? self.backView : self.frontView;
UIView *toView = self.goingToFrontView ? self.frontView : self.backView;


UIViewAnimationOptions transitionDirection = self.goingToFrontView ? UIViewAnimationOptionTransitionFlipFromRight : UIViewAnimationOptionTransitionFlipFromLeft;

[UIView transitionFromView:fromView
toView:toView
duration:1.0
options:transitionDirection
completion:^(BOOL finished) {

[self showButtonTitle];

}];
}

-(void) initFrontViewBackgroundColor{
self.frontView.backgroundColor = [UIColor redColor];
}

-(void) initBackViewBackGroundColor{
self.backView.backgroundColor = [UIColor blueColor];
}

-(void) showButtonTitle{
if(self.goingToFrontView){
self.FlipButton.title = @"前视图";
}else{
self.FlipButton.title = @"后视图";
}
}

@end

当出现’目标机器积极拒绝,无法连接’或svn: Can’t connect to host …时,应依次检查下面各项

1,服务器有没有运行,有没有打开相应端口

如果服务器是svnserve,检查有没有运行svnserve,有没有打开3690端口

如果服务器是apache,检查apahce是否运行,是否打开80端口

检查时可以在服务器运行netstat -na看看相应端口是否在LISTEN

2,防火墙有没有开放相应端口

3,客户端是否可以连接服务器的相应端口

使用命令telnet 服务器IP 相应端口

如:telnet 192.168.0.1 3690

我的服务器是ubuntu的,里面使用的是ufw来作防火墙的,因此可以判定我的这儿端口没有开

执行

1
sudo ufw allow 3690

SVN commit或import时出现 can’t open file ‘txn-current-lock’ permission denied 的原因及解决方法

svn: 提交失败(细节如下):
svn: can’t open file ‘txn-current-lock’ permission denied

或者

svn: 提交失败(细节如下):
svn: Can’t create directory ‘/usr/local/svn/repos/test/db/transactions/1-2.txn’: Permission denied

这个主要原因:在svnadmin create时是root身份,所以,mod_dav_svn就没有write权限等。

解决办法:

1
2
sudo chown -R daemon /var/svnroot/yiiblog
sudo chmod -R 755 /var/svnroot/yiiblog

在ios的开发中,如果自己想调用一个发送短信的方式,其实可以很简答的调用的

短信的发送(SMS)的发送,是使用了一个MessageUI库,然后使用里面的MFMessageComposeViewControllerDelegate协议

我将自己的演示代码贴到下面:

SMSViewController.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//
// SMSViewController.h
// SMS
//
// Created by david on 13-8-2.
// Copyright (c) 2013年 WalkerFree. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>


@interface SMSViewController : UIViewController<MFMessageComposeViewControllerDelegate,UINavigationBarDelegate>
- (IBAction)showSMSPicker:(id)sender;

@end

SMSViewController.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// SMSViewController.m
// SMS
//
// Created by david on 13-8-2.
// Copyright (c) 2013年 WalkerFree. All rights reserved.
//

#import "SMSViewController.h"

@interface SMSViewController ()

@end

@implementation SMSViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)showSMSPicker:(id)sender {

if([MFMessageComposeViewController canSendText]){
[self displaySMSComposeSheet];
}else{
NSLog(@"Device not configured to send SMS.");
}
}

-(void) displaySMSComposeSheet{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;

picker.body = @"你好,今天很想与你共进午餐";
[self presentViewController:picker
animated:YES
completion:NULL];
}

-(void) messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{

// Notifies users about errors associated with the interface
switch (result)
{
case MessageComposeResultCancelled:
NSLog(@"Result: SMS sending canceled");
break;
case MessageComposeResultSent:
NSLog(@"Result: SMS sent");
break;
case MessageComposeResultFailed:
NSLog(@"Result: SMS sending failed");
break;
default:
NSLog(@"Result: SMS not sent");
break;
}

[self dismissViewControllerAnimated:YES completion:NULL];
}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationMaskPortrait);
}
@end

ok,直接运行一下就可以了。模拟器似乎是不能使用的,要在真机上才可以测试的

0%