Gowhich

Durban's Blog

在storyboard中,segue有几种不同的类型,在iphone和ipad的开发中,segue的类型是不同的。

在iphone中,segue有:push,modal,和custom三种不同的类型,这些类型的区别在与新页面出现的方式。

而在ipad中,有push,modal,popover,replace和custom五种不同的类型。

根据这几个特点,同时自己有观看了,斯坦福大学的公开课,里面也是有关于此方面的应用。废话少说,将自己的实例放上来吧。

里面的内容大部分跟课程里面的内容差不多

PsychologistViewController.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
//
// PsychologistViewController.m
// Psychologist
//
// Created by david on 13-5-26.
// Copyright (c) 2013年 david. All rights reserved.
//

#import "PsychologistViewController.h"
#import "happinessViewController.h"

@interface PsychologistViewController ()

@property (nonatomic) int diagnosis;

@end

@implementation PsychologistViewController

@synthesize diagnosis = _diagnosis;

-(void) setAndShowDiagnosis:(int)diagnosis
{
self.diagnosis = diagnosis;
[self performSegueWithIdentifier:@"showDiagnosis" sender:self];
}

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"showDiagnosis"])
{
[segue.destinationViewController setHappiness:self.diagnosis];
}
else if([segue.identifier isEqualToString:@"movie"])
{
[segue.destinationViewController setHappiness:50];
}
else if([segue.identifier isEqualToString:@"teleplay"])
{
[segue.destinationViewController setHappiness:20];
}
else if([segue.identifier isEqualToString:@"cartoon"])
{
[segue.destinationViewController setHappiness:100];
}
}

- (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.
}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}

- (IBAction)flaying:(id)sender
{
[self setAndShowDiagnosis:86];
}

- (IBAction)bite:(id)sender
{
[self setAndShowDiagnosis:70];
}

- (IBAction)play:(id)sender
{
[self setAndShowDiagnosis:20];
}
@end
PsychologistViewController.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//
// PsychologistViewController.h
// Psychologist
//
// Created by david on 13-5-26.
// Copyright (c) 2013年 david. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface PsychologistViewController : UIViewController
- (IBAction)flaying:(id)sender;
- (IBAction)bite:(id)sender;
- (IBAction)play:(id)sender;

@end
faceView.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
//
// faceView.h
// happiness
//
// Created by david on 13-5-23.
// Copyright (c) 2013年 david. All rights reserved.
//

#import <UIKit/UIKit.h>


@class faceView;

@protocol FaceViewDataSource
-(float) smileForFaceView:(faceView *) sender;
@end


@interface faceView : UIView

@property (nonatomic) CGFloat scale;
-(void) pinch:(UIPinchGestureRecognizer *)gesture;

@property (nonatomic, weak) IBOutlet id<FaceViewDataSource> dataSource;

@end
faceView.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
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
//
// faceView.m
// happiness
//
// Created by david on 13-5-23.
// Copyright (c) 2013年 david. All rights reserved.
//

#import "faceView.h"

#define DEFAULT_SCALE 0.90
#define EYE_H 0.35
#define EYE_V 0.35
#define EYE_RADIUS 0.10
#define MOUTH_H 0.45
#define MOUTH_V 0.40
#define MOUTH_SMILE 0.25


@implementation faceView

@synthesize scale = _scale;

-(CGFloat) scale
{
if(!_scale)
{
return DEFAULT_SCALE;
}else{
return _scale;
}
}


-(void) setScale:(CGFloat)scale
{
if(scale != _scale)
{
_scale = scale;
[self setNeedsDisplay];
}
}

-(void) pinch:(UIPinchGestureRecognizer *)gesture
{
if((gesture.state == UIGestureRecognizerStateChanged) || (gesture.state == UIGestureRecognizerStateEnded))
{
self.scale = gesture.scale;
gesture.scale = 1;
}
}


-(void) setup
{
self.contentMode = UIViewContentModeRedraw;
}

-(void) awakeFromNib
{
[self setup];
}

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setup];
}
return self;
}

-(void) drawCircleAtPoint:(CGPoint)p withRadius:(CGFloat)radius inContext:(CGContextRef)context
{
UIGraphicsPushContext(context);
CGContextBeginPath(context);
CGContextAddArc(context, p.x, p.y, radius, 0 , 2*M_PI, YES);
CGContextStrokePath(context);
UIGraphicsPopContext();
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{

//face
CGContextRef context = UIGraphicsGetCurrentContext();

CGPoint midPoint;
midPoint.x = self.bounds.origin.x + self.bounds.size.width / 2;
midPoint.y = self.bounds.origin.y + self.bounds.size.height / 2;


CGFloat size = self.bounds.size.width / 2;
if(self.bounds.size.height < self.bounds.size.width) size = self.bounds.size.height / 2;

size *= self.scale;

CGContextSetLineWidth(context, 5.0);
[[UIColor blueColor] setStroke];

[self drawCircleAtPoint:midPoint withRadius:size inContext: context];

//eye
CGPoint eyePoint;
eyePoint.x = midPoint.x - size * EYE_H;
eyePoint.y = midPoint.y - size * EYE_V;
[self drawCircleAtPoint:eyePoint withRadius:size * EYE_RADIUS inContext:context];
eyePoint.x += size * EYE_H * 2;
[self drawCircleAtPoint:eyePoint withRadius:size * EYE_RADIUS inContext:context];


//mouth
CGPoint mouthStartPoint;
mouthStartPoint.x = midPoint.x - size * MOUTH_H;
mouthStartPoint.y = midPoint.y + size * MOUTH_V;
CGPoint mouthEndPoint = mouthStartPoint;
mouthEndPoint.x += MOUTH_H * size * 2;

CGPoint mouthCP1 = mouthStartPoint;
mouthCP1.x += MOUTH_H * size * 2 / 3;

CGPoint mouthCP2 = mouthEndPoint;
mouthCP2.x -= MOUTH_V * size * 2 / 3;

float smile = [self.dataSource smileForFaceView:self];
if(smile < -1) smile = -1;
if(smile > 1) smile = 1;

CGFloat smileOffset = MOUTH_SMILE * size * smile;
mouthCP1.y += smileOffset;
mouthCP2.y += smileOffset;

CGContextBeginPath(context);
CGContextMoveToPoint(context, mouthStartPoint.x, mouthStartPoint.y);
CGContextAddCurveToPoint(context, mouthCP1.x, mouthCP1.y, mouthCP2.x, mouthCP2.y, mouthEndPoint.x, mouthEndPoint.y);
CGContextStrokePath(context);
// Drawing code
}


@end
happinessViewController.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
//
// happinessViewController.m
// happiness
//
// Created by david on 13-5-23.
// Copyright (c) 2013年 david. All rights reserved.
//

#import "happinessViewController.h"
#import "faceView.h"

@interface happinessViewController ()<FaceViewDataSource>
@property (weak, nonatomic) IBOutlet faceView *faceView;
@end

@implementation happinessViewController


@synthesize happiness = _happiness;
@synthesize faceView = _faceView;

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

-(void) setHappiness:(int)happiness
{
_happiness = happiness;
[self.faceView setNeedsDisplay];
}

-(void) setFaceView:(faceView *)faceView
{
_faceView = faceView;
[self.faceView addGestureRecognizer:[[UIPinchGestureRecognizer alloc] initWithTarget:self.faceView action:@selector(pinch:)]];
[self.faceView addGestureRecognizer:[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleHappinessGesture:)]];
self.faceView.dataSource = self;
}

-(void) handleHappinessGesture:(UIPanGestureRecognizer *)gesture
{
if(gesture.state == UIGestureRecognizerStateChanged || gesture.state == UIGestureRecognizerStateEnded)
{
CGPoint translation = [gesture translationInView:self.faceView];
self.happiness -= translation.y / 2;
[gesture setTranslation:CGPointZero inView:self.faceView];
}
}

-(float) smileForFaceView:(faceView *)sender
{
return (self.happiness - 50.0) / 50.0;
}

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

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}

@end
happinessViewController.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
// happinessViewController.h
// happiness
//
// Created by david on 13-5-23.
// Copyright (c) 2013年 david. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface happinessViewController : UIViewController

@property (nonatomic) int happiness; //0 代表不开心 100 代表开心

@end

应用截图相册地址:http://my.poco.cn/album/album\_show\_photo\_list.htx&user\_id=173673909&set\_hash=3946768073

将UISearchBar放在UINavigationBar之上,实现的过程如下:

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
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.navigationController.navigationBar.tintColor = [UIColor redColor];

//添加左侧的item
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"艺人"
style:UIBarButtonItemStyleBordered target:self
action:@selector(showSelect)];
self.navigationItem.leftBarButtonItem = leftItem;


//导航条的搜索条
_searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0.0f,0.0f,255.0f,44.0f)];
_searchBar.delegate = self;
[_searchBar setTintColor:[UIColor redColor]];
[_searchBar setPlaceholder:@"输入艺人名字"];

//将搜索条放在一个UIView上
UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 44)];
searchView.backgroundColor = [UIColor blueColor];
[searchView addSubview:_searchBar];
self.navigationItem.titleView = searchView;

//设置tableview的代理
self.dataTable.delegate = self;
self.dataTable.dataSource = self;

//加载数据
NSString *path=[[NSBundle mainBundle] pathForResource:@"category" ofType:@"plist"];
self.dataDic = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
}

如果说你的searchbar的位置不对,那么好的我这里高速你应该如何去调整吧:

请你注意一下这条语句:

1
_searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0.0f,0.0f,255.0f,44.0f)];

那么解决的办法就很简单了,只要你修改一个坐标和宽度,或者高度,你就可以任意的设置了。

修改导航栏的背景图片,可按照下面的方法操作:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
UINavigationBar *navBar = self.navigationController.navigationBar;  

#define kSCNavBarImageTag 10
if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{
//if iOS 5.0 and later
[navBar setBackgroundImage:[UIImage imageNamed:@"navbar1.png"] forBarMetrics:UIBarMetricsDefault];
}
else
{
UIImageView *imageView = (UIImageView *)[navBar viewWithTag:kSCNavBarImageTag];
if (imageView == nil)
{
imageView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:@"navbar1.png"]];
[imageView setTag:kSCNavBarImageTag];
[navBar insertSubview:imageView atIndex:0];
[imageView release];
}
}

修改导航栏的背景色的方法,可按照下面的办法来操作:

1
navBar.tintColor = [UIColor greenColor];

源码下载的地址:https://github.com/fxsjy/jieba

演示地址:http://jiebademo.ap01.aws.af.cm/

特点

支持三种分词模式:

  • 精确模式,试图将句子最精确地切开,适合文本分析;
  • 全模式,把句子中所有的可以成词的词语都扫描出来, 速度非常快,但是不能解决歧义;
  • 搜索引擎模式,在精确模式的基础上,对长词再次切分,提高召回率,适合用于搜索引擎分词。

支持繁体分词

支持自定义词典

安装

Python 2.x 下的安装

全自动安装easy_install jieba 或者 pip install jieba
半自动安装:先下载http://pypi.python.org/pypi/jieba/ ,解压后运行python setup.py install
手动安装:将jieba目录放置于当前目录或者site-packages目录
通过import jieba 来引用

Python 3.x 下的安装

目前master分支是只支持Python2.x 的
Python3.x 版本的分支也已经基本可用: https://github.com/fxsjy/jieba/tree/jieba3k

1
2
3
git clone https://github.com/fxsjy/jieba.git
git checkout jieba3k
python setup.py install

算法实现:

基于Trie树结构实现高效的词图扫描,生成句子中汉字所有可能成词情况所构成的有向无环图(DAG)
采用了动态规划查找最大概率路径, 找出基于词频的最大切分组合
对于未登录词,采用了基于汉字成词能力的HMM模型,使用了Viterbi算法

功能

功能 1):分词

jieba.cut方法接受两个输入参数: 1) 第一个参数为需要分词的字符串 2)cut_all参数用来控制是否采用全模式
jieba.cut_for_search方法接受一个参数:需要分词的字符串,该方法适合用于搜索引擎构建倒排索引的分词,粒度比较细
注意:待分词的字符串可以是gbk字符串、utf-8字符串或者unicode
jieba.cut以及jieba.cut_for_search返回的结构都是一个可迭代的generator,可以使用for循环来获得分词后得到的每一个词语(unicode),也可以用list(jieba.cut(...))转化为list
代码示例( 分词 )

1
2
3
4
5
6
7
8
9
10
#encoding=utf-8
import jieba
seg_list = jieba.cut("我来到北京清华大学", cut_all=True)
print "Full Mode:", "/ ".join(seg_list) # 全模式
seg_list = jieba.cut("我来到北京清华大学", cut_all=False)
print "Default Mode:", "/ ".join(seg_list) # 精确模式
seg_list = jieba.cut("他来到了网易杭研大厦") # 默认是精确模式
print ", ".join(seg_list)
seg_list = jieba.cut_for_search("小明硕士毕业于中国科学院计算所,后在日本京都大学深造") # 搜索引擎模式
print ", ".join(seg_list)

Output:

1
2
3
4
【全模式】: 我/ 来到/ 北京/ 清华/ 清华大学/ 华大/ 大学
【精确模式】: 我/ 来到/ 北京/ 清华大学
【新词识别】:他, 来到, 了, 网易, 杭研, 大厦 (此处,“杭研”并没有在词典中,但是也被Viterbi算法识别出来了)
【搜索引擎模式】: 小明, 硕士, 毕业, 于, 中国, 科学, 学院, 科学院, 中国科学院, 计算, 计算所, 后, 在, 日本, 京都, 大学, 日本京都大学, 深造

功能 2) :添加自定义词典

开发者可以指定自己自定义的词典,以便包含jieba词库里没有的词。虽然jieba有新词识别能力,但是自行添加新词可以保证更高的正确率
用法:

1
jieba.load_userdict(file_name) # file_name为自定义词典的路径

词典格式和dict.txt一样,一个词占一行;每一行分三部分,一部分为词语,另一部分为词频,最后为词性(可省略),用空格隔开
范例:
自定义词典:

1
2
3
4
5
6
云计算 5
李小福 2 nr
创新办 3 i
easy_install 3 eng
好用 300
韩玉赏鉴 3 nz

用法示例:

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
#encoding=utf-8
import sys
sys.path.append("../")
import jieba
jieba.load_userdict("userdict.txt")
import jieba.posseg as pseg

test_sent = "李小福是创新办主任也是云计算方面的专家;"
test_sent += "例如我输入一个带“韩玉赏鉴”的标题,在自定义词库中也增加了此词为N类型"
words = jieba.cut(test_sent)
for w in words:
print w

result = pseg.cut(test_sent)

for w in result:
print w.word, "/", w.flag, ", ",

print "\n========"

terms = jieba.cut('easy_install is great')
for t in terms:
print t
print '-------------------------'
terms = jieba.cut('python 的正则表达式是好用的')
for t in terms:
print t

之前: 李小福 / 是 / 创新 / 办 / 主任 / 也 / 是 / 云 / 计算 / 方面 / 的 / 专家 /
加载自定义词库后: 李小福 / 是 / 创新办 / 主任 / 也 / 是 / 云计算 / 方面 / 的 / 专家 /
“通过用户自定义词典来增强歧义纠错能力” — https://github.com/fxsjy/jieba/issues/14

功能 3) :关键词提取

1
jieba.analyse.extract_tags(sentence,topK) #需要先import jieba.analyse

说明

setence为待提取的文本

topK为返回几个TF/IDF权重最大的关键词,默认值为20
代码示例 (关键词提取)

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
import sys
sys.path.append('../')

import jieba
import jieba.analyse
from optparse import OptionParser

USAGE = "usage: python extract_tags.py [file name] -k [top k]"

parser = OptionParser(USAGE)
parser.add_option("-k", dest="topK")
opt, args = parser.parse_args()


if len(args) < 1:
print USAGE
sys.exit(1)

file_name = args[0]

if opt.topK is None:
topK = 10
else:
topK = int(opt.topK)

content = open(file_name, 'rb').read()

tags = jieba.analyse.extract_tags(content, topK=topK)

print ",".join(tags)

功能 4) : 词性标注

标注句子分词后每个词的词性,采用和ictclas兼容的标记法
用法示例

1
2
3
4
5
6
7
8
9
>>> import jieba.posseg as pseg
>>> words = pseg.cut("我爱北京天安门")
>>> for w in words:
... print w.word, w.flag
...
我 r
爱 v
北京 ns
天安门 ns

功能 5) : 并行分词

原理:将目标文本按行分隔后,把各行文本分配到多个python进程并行分词,然后归并结果,从而获得分词速度的可观提升
基于python自带的multiprocessing模块,目前暂不支持windows
用法:

1
2
jieba.enable_parallel(4) # 开启并行分词模式,参数为并行进程数
jieba.disable_parallel() # 关闭并行分词模式

例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import urllib2
import sys,time
import sys
sys.path.append("../../")
import jieba
jieba.enable_parallel(4)

url = sys.argv[1]
content = open(url,"rb").read()
t1 = time.time()
words = list(jieba.cut(content))

t2 = time.time()
tm_cost = t2-t1

log_f = open("1.log","wb")
for w in words:
print >> log_f, w.encode("utf-8"), "/" ,

print 'speed' , len(content)/tm_cost, " bytes/second"

实验结果:在4核3.4GHz Linux机器上,对金庸全集进行精确分词,获得了1MB/s的速度,是单进程版的3.3倍。

其他词典

占用内存较小的词典文件 https://github.com/fxsjy/jieba/raw/master/extra\_dict/dict.txt.small
支持繁体分词更好的词典文件 https://github.com/fxsjy/jieba/raw/master/extra\_dict/dict.txt.big
下载你所需要的词典,然后覆盖jieba/dict.txt 即可或者用jieba.set_dictionary(‘data/dict.txt.big’)

模块初始化机制的改变:lazy load (从0.28版本开始)

jieba采用延迟加载,”import jieba”不会立即触发词典的加载,一旦有必要才开始加载词典构建trie。如果你想手工初始jieba,也可以手动初始化。

1
2
import jieba
jieba.initialize() # 手动初始化(可选)

在0.28之前的版本是不能指定主词典的路径的,有了延迟加载机制后,你可以改变主词典的路径:

1
jieba.set_dictionary('data/dict.txt.big')

例子:

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
#encoding=utf-8
import sys
sys.path.append("../")
import jieba

def cuttest(test_sent):
result = jieba.cut(test_sent)
print " ".join(result)

def testcase():
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
cuttest("我不喜欢日本和服。")
cuttest("雷猴回归人间。")
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
cuttest("我需要廉租房")
cuttest("永和服装饰品有限公司")
cuttest("我爱北京天安门")
cuttest("abc")
cuttest("隐马尔可夫")
cuttest("雷猴是个好网站")

if __name__ == "__main__":
testcase()
jieba.set_dictionary("foobar.txt")
print "================================"
testcase()

第一次配置的时候可按照下面的操作进行:

  • 首先,你必须访问物理控制台。
  • 把ESX主机设为维护模式并从Virtual Center中断开。
  • 连接到ESX主机的控制台。
  • 删除旧的IP(即删除vswif接口),”esxcfg-vswif -d vswif0” (vswif0 你的第一块网卡)
  • 建立一个新的vswif接口及相应的IP地址,
    esxcfg-vswif -a vswif0 -p Service Console -i 192.168.0.100 -n 255.255.255.0 -b 192.168.0.255
    这里:
    -i 是新的IP地址
    -n 是子网掩码
    -b 是广播地址
  • 更新默认网关,”nano /etc/sysconfig/network file”按CTRL+O和回车,然后CTRL+Q退出。
  • 重新启动接口。”esxcfg-vswif -s vswif0″ (禁用vswif0接口),然后”esxcfg-vswif -e vswif0″(开启该接口)。

重新修改下ESX Server 的IP地址,简单描述一下正确的操作过程:

只有简单几个步骤:
命名一: esxcfg-vswif -i 10.0.0.1 -n 255.255.255.0 vswif0 # 修改 Service console 地址
命令二:vi /etc/hosts # 修改机器IP地址
命令三:vi /etc/sysconfig/network # 修改机器名和网关
命令四:service network restart  #使用此命令重启网卡
其中命令四也可以通过重启实现,不建议
IP 修改之后,使用新的IP登录就可以了.

—————————————————————————————————————————————————
其他一些有用的命令,来源于网络:

  • 看你的esx版本。
    vmware -v
  • 列出esx里知道的服务
    esxcfg-firewall -s
  • 查看具体服务的情况
    esxcfg-firewall -q sshclinet
  • 重新启动vmware服务
    service mgmt-vmware restart
  • 修改root的密码
    passwd root
  • 列出你当前的虚拟交换机
    esxcfg-vswitch -l
  • 查看控制台的设置
    esxcfg-vswif -l
  • 列出系统的网卡
    esxcfg-nics -l
  • 添加一个虚拟交换机,名字叫(internal)连接到两块物理网卡,(重新启动服务,vi就能看见了)
    esxcfg-vswitch -a vSwitch1
    esxcfg-vswitch -A internal vSwitch1
    esxcfg-vswitch -L vmnic1 vSwitch1
    esxcfg-vswitch -L vmnic2 vSwitch1
  • 删除交换机,(注意,别把控制台的交换机也删了)
    esxcfg-vswitch -D vSwitch1
  • 删除交换机上的网卡
    esxcfg-vswitch -u vmnic1 vswitch2
  • 删除portgroup
    esxcfg-vswitch -D internel vswitch1
  • 创建 vmkernel switch ,如果你希望使用vmotion,iscsi的这些功能,你必须创建( 通常是不需要添加网关的)
    esxcfg-vswitch -l
    esxcfg-vswitch -a vswitch2
    esxcfg-vswitch -A “vm kernel” vswitch2
    esxcfg-vswitch -L vmnic3 vswitch2
    esxcfg-vmknic -a “vm kernel” -i 172.16.1.141 -n 255.255.252.0
    esxcfg-route 172.16.0.254
  • 打开防火墙ssh端口
    esxcfg-firewall -e sshClient
    esxcfg-firewall -d sshClient
  • 创建控制台
    esxcfg-vswitch -a vSwitch0
    esxcfg-vswitch -A “service console” vSwitch0
    esxcfg-vswitch -L vmnic0 vSwitch0
    esxcfg-vswif -a vswif0 -p “service console” -i 172.16.1.140 -n 255.255.252.0
  • 添加nas设备(a 添加标签,-o,是nas服务器的名字或ip,-s 是nas输入的共享名字)
    esxcfg-nas -a isos -o nas.vmwar.cn -s isos
  • 列出nas连接
    esxcfg-nas -l
  • 强迫esx去连接nas服务器(用esxcfg-nas -l 来看看结果)
    esxcfg-nas -r
    esxcfg-nas -l
  • 连接iscsi 设备(e:enable q:查询 d:disable s:强迫搜索)
    esxcfg-swiscsi -e
  • 设置targetip
    vmkiscsi-tool -D -a 172.16.1.133 vmhba40
  • 列出和target的连接
    vmkiscsi-tool -l -T vmhba40
  • 列出当前的磁盘
    ls -l mfs/devices/disks

猫接路由器用的是直通线,而路由器再分线给交换机用的也是直通线,再由交换机分线给交换机就要用到交叉线了,
直通线的接法就是网线的两端都是568B
交叉线的接法就是网线的一端是568A 一端是568B
568B的排序就是:橙白-1,橙-2,绿白-3,蓝-4,蓝白-5,绿-6,棕白-7,棕-8
568A的排序就是:绿白-1,绿-2,橙白-3,蓝-4,蓝白-5,橙-6,棕白-7,棕-8

关于自定义的UISearchBar的背景图设置,在经过自己查找资料的情况下,发现的问题是,只有代码段,其采用的方式是,重写UISearchBar,然后调用layoutSubviews这个方法。

那么关于自定UISearchBar我采用的方法是类似自定义UITableviewCell的方法,那么接下来这个layoutSubviews的方法,我想大家也就知道该在那里实现了,实现代码如下:

personSearch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
//
// personSearch.h
// xunYi6
//
// Created by david on 13-5-22.
// Copyright (c) 2013年 david. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface personSearch : UISearchBar

@end
personSearch.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
//
// personSearch.m
// xunYi6
//
// Created by david on 13-5-22.
// Copyright (c) 2013年 david. All rights reserved.
//

#import "personSearch.h"
#import <QuartzCore/QuartzCore.h>

@implementation personSearch

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.tintColor = [UIColor whiteColor];
}
return self;
}

-(void) layoutSubviews
{

UITextField *searchField;
NSUInteger numViews = [self.subviews count];
for(int i = 0; i < numViews; i++) {
if([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) { //conform?
searchField = [self.subviews objectAtIndex:i];
}
}
if(!(searchField == nil)) {
searchField.placeholder = @"输入要查找的艺人的名字";

[searchField setBorderStyle:UITextBorderStyleRoundedRect];
[searchField setBackgroundColor:[UIColor whiteColor]];

//自己的搜索图标
NSString *path = [[NSBundle mainBundle] pathForResource:@"GUI_search" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
UIImageView *iView = [[UIImageView alloc] initWithImage:image];
[iView setFrame:CGRectMake(0.0, 0.0, 30.0, 30.0)];
searchField.leftView = iView;


}

[super layoutSubviews];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/

@end

OK!实现过程就是这样的,漂亮的结果就出来了

网上找了好多关于给UISearchBar的取消按钮设置图片的文章,结果就是给力一段代码,让人迷迷糊糊,不知道该放在哪里,我经过测试是这样的

一般你会搜到这样的代码段:

1
2
3
4
5
6
7
8
9
10
for (UIView *searchbuttons in searchBar.subviews)
{
if ([searchbuttons isKindOfClass:[UIButton class]])
{
UIButton *cancelButton = (UIButton*)searchbuttons;
cancelButton.enabled = YES;
[cancelButton setBackgroundImage:[UIImage imageNamed:@"yourImageName"] forState:UIControlStateNormal];
break;
}
}

我这里修改了上述代码,并放在了具体的方法中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//--------------------------------
//开始搜搜
//--------------------------------
-(BOOL) searchBarShouldBeginEditing:(UISearchBar *)searchBar{
[self.searchBar setShowsCancelButton:YES];
for (UIView *searchbuttons in self.searchBar.subviews)
{
if ([searchbuttons isKindOfClass:[UIButton class]])
{
UIButton *cancelButton = (UIButton*)searchbuttons;
cancelButton.enabled = YES;
NSString *path = [[NSBundle mainBundle] pathForResource:@"GUI_cancel_search" ofType:@"png"];
[cancelButton setBackgroundImage:[UIImage imageWithContentsOfFile:path] forState:UIControlStateNormal];
break;
}
}

return YES;
}

因为我这里要执行的操作是,在进行搜索的时候将取消按钮显示出来,这样的话我就只有在这里进行操作了,经过测试绝对是可以执行的。另外这里有一个点就是,我没有使用UIImage的imageNamed方法,因为会有点小问题,你可以去看我的一篇文章UIImage中imageNamed的使用注意

最近查找了关于这个imageNamed的使用方法说明:有几篇文章是这样说的

第一篇文章:http://hi.baidu.com/dongliqian/item/f9a60bdee1dad84fdcf9be6e

在这篇文章里面提到,[UIImage imageNamed: @""] 多次操作之后,应用经常发生内存警告从而导致自动退出的问题,由此看来[UIImage imageNamed:]只适合与UI界面中小的贴图的读取,而一些比较大的资源文件应该尽量避免使用这个接口。

第二篇文章里面是这样说的:http://www.cocoachina.com/bbs/simple/?t27420.html

里面提到“这种方法在application bundle的顶层文件夹寻找由供应的名字的图象 。 如果找到图片,装载到iPhone系统缓存图象。那意味图片是(理论上)放在内存里作为cache的。”

综合以上我觉得,使用这个方法还是需要注意的,建议使用下面这总方法:

1
2
NSString *path = [[NSBundle mainBundle] pathForResource:@"search" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];

PHP针对iPhone和Android设备输出不同的viewport

1
2
3
4
5
6
7
8
9
10
11
12
<?php
//if iphone
$browser = strpos($_SERVER['HTTP_USER_AGENT'], "iPhone");
if (true == $browser) {
$browser = 'iphone';
}

//if android
$android = strpos($_SERVER['HTTP_USER_AGENT'], "Android");
if (true == $android) {
$brower = 'android';
}

html模版

1
2
3
4
5
6
<?php if ($browser == 'iphone') { ?>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
<?php } elseif ($brower == 'android') { ?>
<meta name="HandheldFriendly" content="true" />
<meta name="viewport" content="width=device-width, height=device-height, user-scalable=no" />
<?php } ?>
0%